aspx_beginners thread: File.Exists? FileInfo.Exists?
Message #1 by Cindy.Somerville@h... on Wed, 27 Nov 2002 19:45:12
|
|
I want to ensure that a file exists before I access the file.
I have tried
File.Exists
and
FileInfo.Exists
But for some reason the file is coming up as not existing, when it does
exist.
Can someone tell me why this is happening?
Am I using the right test to ensure that the file exists.
Cindy
Message #2 by Jcriv@a... on Thu, 28 Nov 2002 09:51:46 EST
|
|
If the file is in a 'virtual' directory(ie part of your web site) you might
need to get it's actual full path name by using a call such as
strFullPath = Current.Server.MapPath( strRelativeFileName )
Hope it helps.
Message #3 by "Mark Harwood" <mark@h...> on Fri, 29 Nov 2002 08:07:51 -0000
|
|
Please submit the code you're testing with.
Mark Harwood
-----Original Message-----
From: Cindy.Somerville@h...
[mailto:Cindy.Somerville@h...]
Sent: 27 November 2002 19:45
To: aspx_beginners
Subject: [aspx_beginners] File.Exists? FileInfo.Exists?
I want to ensure that a file exists before I access the file.
I have tried
File.Exists
and
FileInfo.Exists
But for some reason the file is coming up as not existing, when it does
exist.
Can someone tell me why this is happening?
Am I using the right test to ensure that the file exists.
Cindy
Message #4 by <cindy.somerville@h...> on Fri, 29 Nov 2002 8:15:54 -0500
|
|
Hi
Here is the code I have for testing the file.
The file is in the current directory which is not a virtual directory.
The application runs without error when I don't test for file existing.
private string xmlLocation = "News.xml";
FileInfo theFile = new FileInfo(xmlLocation);
if ( theFile.Exists )
{
myDataSet.ReadXml(Server.MapPath(xmlLocation));
return myDataSet;
}
else
{
throw new FileNotFoundException("File not found: ", xmlLocation);
}
---------- Original Text ----------
From: "Mark Harwood" <mark@h...>, on 2002-11-29 3:07 AM:
Please submit the code you're testing with.
Mark Harwood
-----Original Message-----
From: Cindy.Somerville@h...
[mailto:Cindy.Somerville@h...]
Sent: 27 November 2002 19:45
To: aspx_beginners
Subject: [aspx_beginners] File.Exists? FileInfo.Exists?
I want to ensure that a file exists before I access the file.
I have tried
File.Exists
and
FileInfo.Exists
But for some reason the file is coming up as not existing, when it does
exist.
Can someone tell me why this is happening?
Am I using the right test to ensure that the file exists.
Cindy
Message #5 by Cindy.Somerville@h... on Fri, 29 Nov 2002 20:12:08
|
|
Hi
Here is the code that I'm using.
The file is not in a virtual directory.
string path = @"\News\";
string fullPath = "";
fullPath = (Path.GetFullPath(path));
FileInfo theFile = new FileInfo(fullPath.ToString());
if ( ! theFile.Exists )
{
throw new FileNotFoundException("File not found: ", xmlLocation);
}
cindy
Message #6 by "Mark Harwood" <mark@h...> on Sat, 30 Nov 2002 09:09:43 -0000
|
|
Have you tried replacing the server.mappath with the full physical path
Mark harwood
-----Original Message-----
From: cindy.somerville@h...
[mailto:cindy.somerville@h...]
Sent: 29 November 2002 13:16
To: aspx_beginners
Subject: [aspx_beginners] File.Exists? FileInfo.Exists?
Hi
Here is the code I have for testing the file.
The file is in the current directory which is not a virtual directory.
The application runs without error when I don't test for file existing.
private string xmlLocation = "News.xml";
FileInfo theFile = new FileInfo(xmlLocation);
if ( theFile.Exists )
{
myDataSet.ReadXml(Server.MapPath(xmlLocation));
return myDataSet;
}
else
{
throw new FileNotFoundException("File not found: ",
xmlLocation);
}
---------- Original Text ----------
From: "Mark Harwood" <mark@h...>, on 2002-11-29 3:07 AM:
Please submit the code you're testing with.
Mark Harwood
-----Original Message-----
From: Cindy.Somerville@h...
[mailto:Cindy.Somerville@h...]
Sent: 27 November 2002 19:45
To: aspx_beginners
Subject: [aspx_beginners] File.Exists? FileInfo.Exists?
I want to ensure that a file exists before I access the file.
I have tried
File.Exists
and
FileInfo.Exists
But for some reason the file is coming up as not existing, when it does
exist.
Can someone tell me why this is happening?
Am I using the right test to ensure that the file exists.
Cindy
|