469,358 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

FileInfo Issue

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

Feb 5 '06 #1
3 2069
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
"JJ" wrote:
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

Feb 5 '06 #2
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);
}

}
"JJ" <jj****@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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

Feb 5 '06 #3
JJ
great got it to work. Thanks!

JJ

Feb 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ShikariShambu | last post: by
1 post views Thread by Steven J. Reed | last post: by
2 posts views Thread by John Bowman | last post: by
3 posts views Thread by rn5a | last post: by
reply views Thread by comp.lang.php | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.