Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to read HTML/Text file

Status
Not open for further replies.

BrianJH

Programmer
May 26, 2003
26
US
I am Developing a program to get HTML files off of the web and view their source code. So far I have been able to download the file, but I get an error that says "Access to Unnamed File Denied" when I try to read the file.

Here is my code for reading the file:

void CGetWebFileDlg::OnViewfile()
{

CFile myfile;
CFileException error;
CString filename;
char Source[1024];
//Done Initializing variables

//Get file name entered in dialog
m_strFileNameCtrl.GetWindowText(filename);

filename = "C:\\DOCS\\" + filename;
myfile.Open(filename,CFile::modeCreate | CFile::modeWrite,&error);

//HERE IS WHERE I GET THE ERROR
myfile.Read(Source,1024);
//Access to Unnamed File Denied!

//Send the source to the new dialog and initialize
htmldiag.m_Html = Source;
htmldiag.DoModal();
}

I Cleaned the code up a bit(removed error handling code)for easier viewing.

Also, is this the best method for performing this action? If not, could someone let me know a better way?
 
After this line of code:
filename = "C:\\DOCS\\" + filename;

what is the value of "filename"?

-pete
 
filename is used as follows:

CString filename; //initialized

m_strFileNameCtrl.GetWindowText(filename);
//filename equals the text that is in the edit box
//(index.html)

filename = "C:\\DOCS\\" + filename;
//filename equals "C:\DOCS\index.html"

myFile.Open(filename,...)//etc.
 
My bad... you are opening the file in create and write mode and then calling the Read() function.

Not going to work. Try opening the file in CFile::modeRead
Code:
myfile.Open(filename,CFile::modeRead,&error);


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top