What directory path do I use to display an image in a gridview for publishing.

dearness
dearness used Ask the Experts™
on
I have tried what seems like 100 combinations of directory paths to display an image in a Gridview after publishing and I cant get any to work. The images show in development debugging mode but after publishing nothing. The path for the images comes from an Access database field, example....

~\Images\TICK.jpg

The published virtual directory is C:\MRO and the images are in folder C:\MRO\Images

I had a similar problem getting a document from a folder in code, server.mapPath(..
fixed that but this is different.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Source code in developmet .....
<td>E10</td><td>SANDPAPER, NORTON 9&quot;&quot; X 11&quot;&quot; SHEETS 80GR</td><td>C-186*</td><td>177</td><td><img src="Images/TICK.jpg" /></td>

Source code after deployment.....
<td>E10</td><td>SANDPAPER, NORTON 9&quot;&quot; X 11&quot;&quot; SHEETS 80GR</td><td>C-186*</td><td>177</td><td><span></span></td>

Author

Commented:
If I set the NullImageUrl property in the datagridview column it displays correctly when published.

<asp:ImageField DataImageUrlField="PHOTO" HeaderText="PHOTO"
                NullImageUrl="~/Images/nopictureiconweb.gif">
            </asp:ImageField>
Try below code:

<img src="~/Images/TICK.jpg" />
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
Thanks for the reply,
this wont work in development or published.

Author

Commented:
I hope this extra information can help solve the problem.

I added another column and bound it to the same field in the database.

<asp:BoundField DataField="PHOTO" HeaderText="PHOTO" />
            <asp:ImageField DataImageUrlField="PHOTO" HeaderText="PHOTO"
                NullImageUrl="~/Images/nopictureiconweb.gif">
            </asp:ImageField>

In development I get the URL and picture showing, URL shows as  

~/Images/TICK.jpg

After publishing, the URL and picture will not show. For some reason that one database field is not being read, all other columns show correct database data.

Author

Commented:
A small break through with this. I am finding the web server is not displaying the latest data from the database, If I change data in the database columns the changed dont show in the browser. The server is displaying old information!. Since I added the photo column last after testing, it is not being read. IS there something I need to do at the server? I am Caching the data in an application object.

 Dim daDB As New dsMROTableAdapters.tblMROTableAdapter
        Dim dtDB As New System.Data.DataTable
        dtDB = daDB.selectFullDatabase
        'get the pm information from strongly typed data adapter  
        Application.Lock()
        Application("dtDatabase") = dtDB
        Application.UnLock()


Protected Sub btnMRO_Search_Click(sender As Object, e As System.EventArgs) Handles btnMRO_Search.Click
        Dim modifiedText As String
        Dim dtMRO As New DataTable
        dtMRO = Application("dtDatabase")
        'search for MRO number
        If txtMRO_Search.Text <> "" Then..................



I get the feeling this is where I am going wrong?

Author

Commented:
OK, I have just given myself a hard lesson on how using application caching while testing works. The cache is doing exactly what its is supposed to do.
Great, you did it yourself.

One point to can be noticed here that the ~ sign works only for the serverside controls not html controls.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial