Click here to Skip to main content
15,912,316 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to enumerate taskbar buttons Pin
DevMentor.org3-Aug-07 3:53
DevMentor.org3-Aug-07 3:53 
GeneralRe: How to enumerate taskbar buttons Pin
FlyingBear3-Aug-07 5:46
FlyingBear3-Aug-07 5:46 
GeneralRe: How to enumerate taskbar buttons Pin
DevMentor.org3-Aug-07 7:47
DevMentor.org3-Aug-07 7:47 
QuestionQ: Control Notification handling Pin
_Pinux_2-Aug-07 23:19
_Pinux_2-Aug-07 23:19 
AnswerRe: Q: Control Notification handling Pin
_Pinux_3-Aug-07 1:17
_Pinux_3-Aug-07 1:17 
GeneralRe: Q: Control Notification handling Pin
Mark Salsbery3-Aug-07 8:03
Mark Salsbery3-Aug-07 8:03 
GeneralRe: Q: Control Notification handling Pin
_Pinux_8-Aug-07 3:18
_Pinux_8-Aug-07 3:18 
Questiondata not write at .txt file Pin
Y_Kaushik2-Aug-07 22:40
Y_Kaushik2-Aug-07 22:40 
Hello Guru Jiiiiiiiiii's

I am making a application in VC++(MFC-Modal Dialog based).And i don't know
file handling ........The question i am writing here i have already post here
but I am sending my code also. my question is below . Plz help me

Actually I am making a file field ( Mense when user click browse button
all HD display and he/she can attach his .txt document ) That .txt doc
will be save at a file which is created in C:Drive in a folder ( it can any other place also )

I have done its Most of work like i can read file create new file also
but i am unable to write that data in to newly created file.

I don't know where i am making wrong . I know its vewry basic . But i am also know i am also very begginner in file handling
My whole code That i have write for this is below


CString str;
int ids;
CFileDialog Obj(TRUE);
if(Obj.DoModal() ==IDC_BUTTON3)
{
m_Upload = Obj.GetFileName();
}
str.Empty();
str = Obj.GetPathName();
SetDlgItemText(IDC_EDIT1,str); //write file path with name at edit box

CString strLine = "";
CString buffer = "";
CStdioFile fileObj,filewrite;
CString fname;


fileObj.Open(str, CFile::modeRead | CFile::shareDenyWrite);
fname = fileObj.GetFileName();

while(fileObj.ReadString(strLine))
{
fileObj.ReadString(strLine);
buffer += strLine + "\r\n";
}
fileObj.Close();
// MessageBox(buffer);
SetDlgItemText(IDC_EDIT3,buffer);////write all data at another edit box


fileObj.Open("c:\\UserFolder\\" + fname + ".txt",CFile::modeCreate,NULL);

CString dataStr;

GetDlgItemText(IDC_EDIT3,dataStr);
CStdioFile myFile;
CFileException e;
CString strFileName =str;


if(! myFile.Open( strFileName, CStdioFile::modeCreate | CStdioFile::modeWrite
| CStdioFile::modeNoTruncate, &e ) )
{
CString failCause = "Unable to open file. Reason : ";
switch (e.m_cause) {
case CFileException::none:
failCause += "No error occurred.";
break;

case CFileException::generic:
failCause += "An unspecified error occurred.";
break;

case CFileException::fileNotFound:
failCause += "The file could not be located.";
break;

case CFileException::badPath:
failCause += "All or part of the path is invalid.";
break;

case CFileException::tooManyOpenFiles:
failCause += "The permitted number of open files was exceeded.";
break;

case CFileException::accessDenied:
failCause += "The file could not be accessed.";
break;

case CFileException::invalidFile:
failCause += "There was an attempt to use an invalid file handle.";
break;

case CFileException::removeCurrentDir:
failCause += "The current working directory cannot be removed.";
break;

case CFileException::directoryFull:
failCause += "There are no more directory entries.";
break;

case CFileException::badSeek:
failCause += "There was an error trying to set the file pointer.";
break;

case CFileException::hardIO:
failCause += "There was a hardware error.";
break;

case CFileException::sharingViolation:
failCause += "SHARE.EXE was not loaded, or a shared region was locked.";
break;

case CFileException::lockViolation:
failCause += "There was an attempt to lock a region that was already locked.";
break;

case CFileException::diskFull:
failCause += "The disk is full.";
break;

case CFileException::endOfFile:
failCause += "The end of file was reached.";
break;

default:
failCause += "Unknown cause.";
break;
}
AfxMessageBox(failCause);
}
else
{
myFile.SeekToEnd();
CString strLine = dataStr;
strLine += "\r\n";
myFile.WriteString(strLine);

// myFile.WriteString(dataStr);

myFile.Close();
}



I write that all code with the help of net also its work almost fine But
The main task i.e write all data at file in userfolder is not perform
Please told me where i am wrong




Regard's
Kaushik

AnswerRe: data not write at .txt file Pin
Hamid_RT2-Aug-07 22:51
Hamid_RT2-Aug-07 22:51 
GeneralRe: data not write at .txt file Pin
Christian Graus2-Aug-07 22:56
protectorChristian Graus2-Aug-07 22:56 
GeneralRe: data not write at .txt file Pin
Hamid_RT2-Aug-07 23:06
Hamid_RT2-Aug-07 23:06 
GeneralRe: data not write at .txt file Pin
Y_Kaushik2-Aug-07 23:07
Y_Kaushik2-Aug-07 23:07 
AnswerRe: data not write at .txt file Pin
CPallini2-Aug-07 22:56
mveCPallini2-Aug-07 22:56 
GeneralRe: data not write at .txt file Pin
Y_Kaushik2-Aug-07 23:10
Y_Kaushik2-Aug-07 23:10 
AnswerRe: data not write at .txt file Pin
KarstenK2-Aug-07 22:57
mveKarstenK2-Aug-07 22:57 
AnswerRe: data not write at .txt file Pin
Hamid_RT2-Aug-07 23:05
Hamid_RT2-Aug-07 23:05 
GeneralRe: data not write at .txt file Pin
Y_Kaushik2-Aug-07 23:13
Y_Kaushik2-Aug-07 23:13 
GeneralRe: data not write at .txt file Pin
Y_Kaushik2-Aug-07 23:19
Y_Kaushik2-Aug-07 23:19 
GeneralRe: data not write at .txt file Pin
Hamid_RT3-Aug-07 1:10
Hamid_RT3-Aug-07 1:10 
GeneralRe: data not write at .txt file Pin
Anurag Gandhi2-Aug-07 23:17
professionalAnurag Gandhi2-Aug-07 23:17 
QuestionRe: data not write at .txt file Pin
CPallini2-Aug-07 23:22
mveCPallini2-Aug-07 23:22 
GeneralRe: data not write at .txt file Pin
Hamid_RT3-Aug-07 1:10
Hamid_RT3-Aug-07 1:10 
AnswerRe: data not write at .txt file Pin
Anurag Gandhi2-Aug-07 23:14
professionalAnurag Gandhi2-Aug-07 23:14 
GeneralRe: data not write at .txt file Pin
Y_Kaushik2-Aug-07 23:31
Y_Kaushik2-Aug-07 23:31 
GeneralRe: data not write at .txt file Pin
Anurag Gandhi3-Aug-07 0:14
professionalAnurag Gandhi3-Aug-07 0:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.