Problem with File.Exist

J

Jeff

Hey

ASP.NET 2.0

Below is the code I have trouble with. I've placed some pictures in the
~/Network/Images/Fullsize/ folder in my project. The problem is that File
Exist always return false (it execute the ELSE block, despite the fact that
~/Network/Images/Fullsize/" + Profile.UserName + ".png" exist)

if (File.Exists("~/Network/Images/Fullsize/" + Profile.UserName + ".png"))
{
imgProfile.ImageUrl = "~/Network/Images/Fullsize/" + Profile.UserName +
".png";
}
else
{
imgProfile.ImageUrl = "~/Network/Images/Fullsize/nopicture.png";
}

What am I doing wrong here?

Jeff
 
R

Rajko Bogdanovic - DX Squad

Below is the code I have trouble with. I've placed some pictures in the
~/Network/Images/Fullsize/ folder in my project. The problem is that File
Exist always return false (it execute the ELSE block, despite the fact that
~/Network/Images/Fullsize/" + Profile.UserName + ".png" exist)

if (File.Exists("~/Network/Images/Fullsize/" + Profile.UserName + ".png"))

I would try with Server.MapPath( "~/Network...." ) to get the physical
path of the file. If it doesn't work, try losing tilde (~). I don't
think it would work what's it meant to do in the codebehind.

rb
 
E

Eliyahu Goldin

Only aspx pages understand the ~ syntax. File.Exists doesn't. MapPath
("Network...") will do the trick.
 

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,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top