ASP.NET - Can't get an image to display - Asked By Annie X on 10-May-10 07:03 AM

Hi, hope you can help me i'm in a bit of a pickle,

I am using Visual Studio 2008 and I created a new web site (File > New Web Site) located at C:\inetpub\wwwroot\Databases\InfoScreens

Then in the web page (.aspx) i added the html for the image e.g. <img src="Images/AA.jpg" alt="ss" />

which works fine but if I try and link to an image outside of the project folder (InfoScreens) the image will not display e.g. <img src="C:\inetpub\wwwroot\xxx\AAA.jpg" alt="ss" />

I have tried removing 'C:\inetpub\wwwroot' but the issue is not resolved.

Any idea what i should do?

All the best
Annie X

Phivos Stylianides replied to Annie X on 10-May-10 07:17 AM
Annie X replied to Phivos Stylianides on 10-May-10 07:25 AM
Thanks but it didn't work. In the past removing C:/inetpub/wwwroot from the path and replaying / with \ was enough for it to work. Could this be a permissions thing.
Sagar P replied to Annie X on 10-May-10 07:28 AM
It is not a good practice to hard-code physical file paths (such as C:\Website\MyApplication) into your application because the paths can change if you move or deploy your application. However, ASP.NET provides you with ways to get any physical file path within your application programmatically. You can then use the base file path to create a full path to the resource you need. The two most commonly used ASP.NET features for determining a file path are properties of the http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx object that return path information, and the http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx method.

http://msdn.microsoft.com/en-us/library/ms178116.aspx

But if you want then you have to give it like this: ->

<img src="file///C:/inetpub/wwwroot/xxx/AAA.jpg" alt="ss" />

Or

<img src="url('file///C:/inetpub/wwwroot/xxx/AAA.jpg')" alt="ss" />
Phivos Stylianides replied to Annie X on 10-May-10 07:34 AM
Yes possibly, you should give permission to ASP.NET to read and list directory contents and off course read access to the files. The correct format however to use in web apps is with / instead of \ with the scheme at the beginning to be certain that all browsers and technologies will understand it.
Goniey N (Mr. G) replied to Annie X on 10-May-10 07:36 AM
//Try Below Code, Here You Want To Use Image File From The Local Machine So You Must Enter The Whole Path Of That File Like :

<img src="file://C:/inetpub/wwwroot/xxx/AAA.jpg" alt="ss" />


This Will Work Perfectly...