Problem loading images

  • Thread starter Thread starter Clifford Williamson
  • Start date Start date
C

Clifford Williamson

All,

Thank you very much in advance for any help you can give. I have a
website dedicated to holding and maintaining employee data which
includes pictures used for ID badges. I am having a problem with
getting images to load and display properly from my .NET server. I
have been able to insert, update, select, and delete images (jpeg's)
from/to the SQL2000 database without issue. The problem is when it
gets displayed in IE, it often doesn't display a picture at all or it
brings up an older image from a previously selected name from my
listbox. It will often display the same picture several times before
changing to one from a person it selected earlier on the page. The
strange part is that when I debug/run the page from VB it works great.
The images all load and display as they should. All my images are
loaded to and from a memorystream and my picturebox URL points to an
ASPX page that reads the memorystream and outputs that stream to the
box. It's making me crazy at this point because I'm uncertain why it
will work in the debugging enviroment and not work in a live
situation. Any help or tips on this is greately appreciated.
I will post any part of code needed to add clarity.
 
Hi Clifford,

Did you set the content type of your output stream? Also you can add headers to prevent caching of your image by browsers and proxies.
Can you post the few lines of code that send the image to the client?

Regards,
Martin Kulov
www.codeattest.com
 
Here is the code for the picture insertion page. I do not modify the
HTML at all for this page.

Dim imgLoadJpeg As New Bitmap(mLoadedPic)
Dim DisplayedPic As New Bitmap(GetThumbnail(imgLoadJpeg, 150))
Response.ContentType = "image/jpeg"
DisplayedPic.Save(Response.OutputStream,
Imaging.ImageFormat.Jpeg)
imgLoadJpeg.Dispose()
DisplayedPic.Dispose()
Page.Dispose()

mLoadedPic is the memorystream containing the image
GetThumbnail is a function used to modify the picture to fit into the
picturebox properly.

I have two pictureboxes on this page using identical code for each. I
used to have them combined on a single page but I felt it better to
seperate the code for now due to this problem.
 
Quite probably a caching problem on the enclosing HTML page. Make sure
that you have preventing caching, either with the proper meta tags (lot of
contradictory information on that subject on the internet; see
http://support.microsoft.com/kb/263730/EN-US/ for one of many exemples) or
by setting the "Set for newer versions of stored pages" to "Every visit to
the page", under the settings for "Temporary Internet Folder".

Using https instead of http should also solve your problem.

S. L.
 
It's working now... Here is what I added to the preRender code for the
picturebox which solved the caching issue:

Dim d As Date = Now()
imgLoadPic.ImageUrl = "FilePicture.aspx?Time=" & d

This made the URL for the image unique everytime which forced IE to
reload the image everytime the page was reloaded.

Thank you all for your help and suggestions.
 
Back
Top