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, e.g.:
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.
精彩评论