0

Trying to display an image in the webpage tried like below.

Image1.ImageUrl = "C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";

Image2.ImageUrl = "C:\\Users\\naresh\\Desktop\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";

Second one Worked but first one didn't. I think the problem is with the spaces in the path. How can I resolve this problem?

6
  • Have you tried replacing spaces with %20 ? Also, absolute path's aren't a good idea. Use relative instead Commented Jun 28, 2011 at 12:49
  • I see a redundant folder in the path ...\\Vacancy\\Vacancy\\... Can you make sure the path is actually correct? Put it into the run window and see if windows will find the file. Commented Jun 28, 2011 at 12:50
  • If you try to read that first file in to a byte array, do you get any errors, like maybe an access denied or file not found? Commented Jun 28, 2011 at 12:50
  • I dont think the spaces are the problem, is it the same image in both cases? Commented Jun 28, 2011 at 12:50
  • @asawyer:No problem in the path.Even I checked in the browser it displayed correctly. Commented Jun 28, 2011 at 12:51

6 Answers 6

2

Why do you not use a relative path to the location of your site? The path will be shorter and when you will port the web site on production server the image will still work (if the image is port to the server)

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

2 Comments

Can you explain me how to do it?
Consider "\" as the root of your site. As the root of your site seam to be "C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\" replace it by "\". With that your file will be place at : "\Files\3\710d7a38-5a4d-44fc-883f-5996150ba507.jpg"
0

May be with the Vacancy which you have given two times. Check it, if its the mistake.

Comments

0

You can try to replace the spaces with %20.

But I wonder if that's the problem because the image is located at your local disk. Is this webpage only running on your local machine? Does the image exist?

2 Comments

No, in path we should not replace space with  . it looks he has path issue
I already updated my post, I was confusing %20 with   :)
0

Put quoted quotation marks into the string, e.g.:

Image1.ImageUrl = "\"C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg\"";

Comments

0

Try giving the virtual directory path (create a virtual directory for the image folder. If it is in the root itself use the http://systemName/virtualDirectoryName/ImageFolder/image1.jpg) instead of physical path as follows:

  Image1.ImageUrl=http://systemName/virtualDirectoryName/ImageFolder/image1.jpg

Hope this helps..

1 Comment

This is anyway not good, it breaks if you deploy the web application in another website, server, virtual directory. Server.MapPath is the solution, passing to it a relative path.
0

You are doing anyway very bad things in there. You should use Server.MapPath to resolve dynamically an IIS relative path into the file system path and you should not, never ever, load an image from the user's folders.

Put the image inside a subfolder in your web application, like for example create a folder called images at the same level where your aspx pages are.

1 Comment

` img = rdr["ImagePath"].ToString();` img = Server.MapPath(@img); Image1.ImageUrl=img;

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.