Hello,
most of the stuff is already implemented, but I could change it, if there is a better way.
The goal is that the user can upload one Logo, and this Logo is used on the website.
I have a picture box and a upload button. and following functionality (snippet):
public Init() { _companyFolderAbs = Path.GetFullPath(Path.GetDirectoryName(Application.ExecutablePath) + @"\..\Resources\Uploaded_Files\" + _kundenNummer + "_" + _firmenName); _companyFolderRes = "Resources\\Uploaded_Files\\" + _kundenNummer + "_" + _firmenName; this.logoPictureBox.ImageSource = _companyFolderRes + "\\Logo.png"; } private void UploadLogo(HttpPostedFile httpPostedFile) { string logoFile = "Logo.png"; MemoryStream mem = new MemoryStream(); httpPostedFile.InputStream.CopyTo(mem, 1024); mem.Position = 0; UploadStream(mem, logoFile); } private void UploadStream(Stream stream, string uploadFileName) { string path = Path.Combine(_companyFolderAbs, uploadFileName); using (FileStream outputFileStream = new FileStream(path, FileMode.Create)) { stream.CopyTo(outputFileStream); } }
The Upload successfully overwrites the file. The Part that is missing is that the pictureBox then should use the new file.
I know it’s possible to set the Image from a Stream, but it would be easier to tell the App that the Resource / the file changed and needs reloading.
mem.Position = 0; Image newLogo = Image.FromStream(mem); this.logoPictureBox.Image = newLogo;
Or do I always have to use a Stream to show a Logo if it’s possible that it will change? The problem is that even when I close and reopen the form, the old image is still cached. I tried stuff like Refresh(), Recreate(), Unsetting and Resetting the ImageSource, without success. But it seems when I press F5 it uses the new file.
Thanks in advance
If you use
this.logoPictureBox.ImageSource = _companyFolderRes + "\\Logo.png";
Then it’s a URL which is entirely managed by the browser. A common technique in web development is to add a cache buster argument: “\\Logo.png?v={version}”. Where version can be anything that changes.
If you use the Image property it gets updated automatically since Wisej adds the timestamp of the last update. I tested it and it works fine here.
Hi Sascha
For better understand you case
A. You have a logo on a folder of the app, name Logo.png that is used in a pictureBox
B. The user update with new image file, owerwriting the previous file with the same name but diferente image
C. The app not refresh the old image on pictureBox, until only he done a F5
I understand you correctly?
regards
Please login first to submit.