简体   繁体   中英

Problem in displaying image in the web page

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?

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)

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

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?

Put quoted quotation marks into the string, eg:

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

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..

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM