Image is not displayed to take a path from web.config file
Hi,
I am using Asp.Net 3.5 application. I need to show the images when upload the file. So i saved the file in the application path and show it in the web browser. But when i publish the file the path is mismatched. Because i am using server.mappath. When publish the folder it is in different path. So i am using web.config now to put the path, and take a path from "AppSettings.ConfigurationManager". It take correct path and save it. But i load this file path to imgImage.ImageURL = filepath, it doesnt show or displaying in the browser. What is the problem here?
When using server map path it working fine. But if i take a path from web.config file it is not displaying. I wasted one day for this one. Help me experts. I am awaiting for your response.
Regards
Guvera
Re: Image is not displayed to take a path from web.config file
You should not use your web.config file to store these file paths. Web.config as it's name suggests is for your web applications configeration settings not storing data.
That however is not the problem. If all uploaded images are stored in the same folder then you know the location so you only need to store the image name.
If the images where in a folder called photos that was in the website root directory the url would be.
<img src='/photos/imagename' />
You can bind all images in a folder to a grid like this (note the path is /photos/ in code and grid imagefield)
Code:
Dim dr As New DirectoryInfo(Server.MapPath("/photos/"))
gridView1.DataSource = dr.GetFiles
gridView1.DataBind()
Code:
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True">
<Columns>
<asp:ImageField DataImageUrlField="name" ControlStyle-Width="100" DataImageUrlFormatString="/photos/{0}">
</asp:ImageField>
</Columns>
</asp:GridView>
Re: Image is not displayed to take a path from web.config file
you should be using paths that are relative to the page... do NOT use Server.MapPath ... that gives you a path like "C:\wwwroot\inetpub\html\website\....." which no browser will be able to display. Which is why it's not working for you.
-tg