File Exists error

Gibou

Active member
Joined
Mar 4, 2009
Messages
25
Location
Paris
Programming Experience
5-10
Hi,

I'm using .NET 2.0 for this application.

Before loading an xml file, i would like to be sure that the file exists.
So I've that :

VB.NET:
if File.Exists(CoreApplication.ApplicationPath & _xml_file)

where CoreApplication.ApplicationPath contains that : System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

and _xml_file contains (for instance) : xml/toto.xml

When I go through the directory returned by CoreApplication.ApplicationPath, indeed, there is no folder "xml" but in my architecture, there is one !

I don't understand, need some help :)

Thanks
 
If you look at what string ApplicationPath actually returns you will see why. If you don't, look harder.

Try this instead:
VB.NET:
Dim path As String = IO.Path.Combine(CoreApplication.ApplicationPath, _xml_file)
 
Nope, still not.

The output path is this one: file:\c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\project-name\3b594c54\3cb46ac5\

When I look at the final folder, I see anything but folders "Assembly", "hash" and "uploads" and current files. It seems normal that it doesn't find the xml file because it is nowhere but, so, where can I find it ?

I don't see css files but it has found them so, it could find my xml file.
 
I see, then moving thread to more appropriate ASP.Net section of forums. There were no indication you were working on a web application.

Use the MapPath function:
Returns the physical file path that corresponds to the specified virtual path on the Web server.
VB.NET:
Dim path As String = Server.MapPath("xml/toto.xml")
 
Back
Top