FileInfo Issue

J

JJ

I have the following code running in a test asp.net app locally on my
xp system and I can't get the FileInfo.Exist to recognize that the file
is in the folder defined in code. What do I need to set in order for
this to work?

string sFullPath = @"\DocTemp\TestDoc.doc";

if(new FileInfo(sFullPath).Exists)
{
sFullPath = sFullPath.Replace(@"\", @"/");

}

JJ
 
K

Ken Cox - Microsoft MVP

It sounds like the web server doesn't know where your page is relative to
the web directory. What does this return?

protected void Page_Load(object sender, EventArgs e)
{
string sFullPath =Server.MapPath(@"DocTemp\TestDoc.doc");

if (new System.IO.FileInfo(sFullPath).Exists)
{
sFullPath = sFullPath.Replace(@"\", @"/");
Response.Write(sFullPath);
}

}
 
G

Guest

Hi JJ,

I suppose DocTemp\TestDoc.doc is in virtual directory. But file system
requires physical directory.

You can try:

string sFullPath = @"\DocTemp\TestDoc.doc";
// or maybe it’s in a relative path
string sFullPath = @"DocTemp\TestDoc.doc";
string physicalPath = Server.MapPath(sFullPath)

if (System.IO.File.Exists(physicalPath))
{
// Process
}


HTH

Elton Wang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top