How to Refresh an Image in ASP.NET Automatically
by
Doug
Updated June 27, 2011
You may need to have an image refreshed automatically on a web page in ASP.NET to get the latest image. One instance where you might want the fresh image is if you upload an image that has the same file name as an already existing image file on the server, and when the page is Redirected or reloaded, you still see the old image, since it is cached.
To get the latest image file in ASP.NET you can simply add a querystring to the end of the image file name that changes. An easy way to do this is to just add the current DateTime to a querystring. For example:
StoreLogoImage.ImageUrl = "~/someImage.jpg?refreshTime=" + Server.UrlEncode(DateTime.Now.TimeOfDay.ToString());
Because the file name with the TimeOfDay querystring will be different each time the page is refreshed, the latest image will be retrieved, instead of the cached image.