1

For some strange reason my picture is not loading at runtime:

        string path = Server.MapPath("./abc.jpeg");
        Response.Write("the path is:");
        Response.Write(path);

        img_ProfilePic.ImageUrl = path;

As you see from above code, I have verified that the path is correct.

Also the image is only 20 KB and is JPEG.

My environment is VS 2008 C#

Thanks

3 Answers 3

1

Server.MapPath returns the physical (file system) path.

Image.ImageUrl requires a virtual path (or relative/absolute URL). You should use it like this for example:

img_ProfilePic.ImageUrl = "~/images/abc.jpeg";
img_ProfilePic.ImageUrl = "../abc.jpeg";
img_ProfilePic.ImageUrl = "http://www.host.com/abc.jpeg";

More on web project paths (check the Server Controls section which is specific to your problem): http://msdn.microsoft.com/en-us/library/ms178116.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

Right click on the "broken image" icon, and copy and paste the path into your browser. Do you get the image, a "broken image" or a 404?

Are you testing locally?

1 Comment

Actually, you can disregard my answer. The other "Maxim Gueivandov" is correct.
0

Replace string path = Server.MapPath("./abc.jpeg"); with string path = Server.MapPath("~/abc.jpeg");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.