Problem with File.Exist

  • Thread starter Thread starter Jeff
  • Start date Start date
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
 
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
 
Only aspx pages understand the ~ syntax. File.Exists doesn't. MapPath
("Network...") will do the trick.
 
Back
Top