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

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top