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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File is ther but FileNotFound Exception is comming

Status
Not open for further replies.

VenkatRastapuram

Programmer
Oct 24, 2003
46
IN
Hello Sir,

I am developing a application in .NET compact Framework.
There is a file DataFile.xml. It is there in the local directory but there is a FileNotFound Exception while reading the file.

System.IO.Path.GetFullpath("DataFile.xml");

is returning a complete path which is a string.

the path is displayed in the messagebox also.

But it is giving a FileNotFound Excepiton while reading that file. similar case with all the files in the directory

for eg:

try
{
string filepath = System.IO.Path.GetFullPath("DataFile.xml");

System.IO.FileStream filereader = File.OpenRead(filepath);

}
catch(Exception e)
{
MessageBox.show(e.message());
}

the above code is giving FileNotFound Exception

File is there and I checked the the file names also.

Please try to solve my problem,Urgent

Regards,
R.Venkatesh
MakeLogic
venkat@makelogicmldb.com
 
The file or directory passed to the GetFullPath() method is not required to exist!.
For example, if c:\temp\mydir is the current directory, calling GetFullPath on a file name such as test.txt returns c:\temp\mydir\test.txt. The file need not exist but you get the full path !.
Put your file where the .exe is located and retry your code.
So before you open the file check if it exists like here:

try
{
string filepath = System.IO.Path.GetFullPath("DataFile.xml");
if (File.Exists(filepath))
{
System.IO.FileStream filereader = File.OpenRead(filepath);
}
else
{
MessageBox.Show( filepath + " does not exist");
}
}
catch(Exception e)
{
MessageBox.Show(e.GetType() + e.Message);
}
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top