DataconsultGent
asked on
Image refresh file IO problem or cache or something else?
I've read the topic https://www.experts-exchange.com/questions/23066709/Image-does-not-refresh-on-Page.html but my problem isn't solved with it.
Is there any way to detect if file IO is completed?.
I have the same problem. I choose first a year and then I see a gridview with all the pictures of persons in that year. I select a person and click a browse button, choose my file and upload my file by clicking a button. The code behind the file uploads the file and then refreshes my gridview (gridview.databind) and in this gridview I see then the old picture. If I hit F5 of my browser then I see the new uploaded picture.
When there is no original picture available for a person I display a "No image available"-image. when I upload a picture for such person without original picture and when the gridview refreshes, the new picture is there. So I guess it couldn't be a file IO completion problem?
Response.redirect is not an option for me because then my page loads from the beginning. Before I see my gridview I need to choose first a "Year" from a dropdownlist
Then I thought it could be a cache problem, but after reading and testing all suggestions from http://www.syncfusion.com/FAQ/aspnet/web_c25c.aspx I'm not sure, because when i do the following:
********
Dim objItem As DictionaryEntry
For Each objItem In Cache
Response.Write (objItem.Key.ToString ())
Next
********
I don't get anything on my screen, which looks like there is nohting in the cache.
What else could it be then?
Kind regards
Is there any way to detect if file IO is completed?.
I have the same problem. I choose first a year and then I see a gridview with all the pictures of persons in that year. I select a person and click a browse button, choose my file and upload my file by clicking a button. The code behind the file uploads the file and then refreshes my gridview (gridview.databind) and in this gridview I see then the old picture. If I hit F5 of my browser then I see the new uploaded picture.
When there is no original picture available for a person I display a "No image available"-image. when I upload a picture for such person without original picture and when the gridview refreshes, the new picture is there. So I guess it couldn't be a file IO completion problem?
Response.redirect is not an option for me because then my page loads from the beginning. Before I see my gridview I need to choose first a "Year" from a dropdownlist
Then I thought it could be a cache problem, but after reading and testing all suggestions from http://www.syncfusion.com/FAQ/aspnet/web_c25c.aspx I'm not sure, because when i do the following:
********
Dim objItem As DictionaryEntry
For Each objItem In Cache
Response.Write (objItem.Key.ToString ())
Next
********
I don't get anything on my screen, which looks like there is nohting in the cache.
What else could it be then?
Kind regards
ASKER
Dear renjurdevan,
This doesn't help. I don't see my new uploaded picture in my gridview.
Attached is my code on page load and when the button is clicked
I upload the original picture of the person, I save them twice (small (width=68 for 96dpi) and big (width=223 fpr 300dpi)) and then I delete the original uploade file, after that I refresh my gridview
I've also added my code on Gridview_RowDatabound
This doesn't help. I don't see my new uploaded picture in my gridview.
Attached is my code on page load and when the button is clicked
I upload the original picture of the person, I save them twice (small (width=68 for 96dpi) and big (width=223 fpr 300dpi)) and then I delete the original uploade file, after that I refresh my gridview
I've also added my code on Gridview_RowDatabound
Protected Sub UploadClick(ByVal sender As Object, ByVal e As System.EventArgs)
If DdlStudent.SelectedItem.Value <> 0 Then
'Variabele voor bestandslocatie
Dim strPath As String = "E:\Websites\ryedb.uploads\images\in\" & Profile.District & "\"
Dim strUploadedFile, strUploadedFileExtensie, strFile, strFullPath, strFullPathNewSmall, strFullPathNewLarge As String
Dim canvas As New Canvas()
Dim graph As New Graphic()
Dim rect As New XRect()
'Bestandsnaam en extensie van het opgeladen bestand
strUploadedFile = FileUpload1.PostedFile.FileName
strUploadedFileExtensie = Right(strUploadedFile, 3)
'District uit Profile halen => nodig om bestand een naam te geven
Dim strDistrict As String = Profile.District
'Nieuwe bestandsnaam
strFile = strDistrict & "_in_" & DdlStudent.SelectedItem.Value 'Idin student uit dropdownlijst toevoegen
strFullPath = strPath & strFile & "." & strUploadedFileExtensie
strFullPathNewSmall = strPath & strFile & "s.jpg"
strFullPathNewLarge = strPath & strFile & "l.jpg"
Try
If UCase(strUploadedFileExtensie) = "JPG" Or UCase(strUploadedFileExtensie) = "BMP" Or UCase(strUploadedFileExtensie) = "EPS" Or UCase(strUploadedFileExtensie) = "GIF" Or UCase(strUploadedFileExtensie) = "TIF" Then
FileUpload1.PostedFile.SaveAs(strFullPath)
'1) Foto verkleinen naar breedte = 68 en in 96dpi
graph.SetFile(strFullPath)
rect.String = graph(1).Rectangle
canvas.Clear()
canvas.Width = 68
canvas.Height = (68 * rect.Height) / rect.Width
canvas.DrawFile(strFullPath, "size=" & canvas.Width & "," & canvas.Height)
canvas.SaveAs(strFullPathNewSmall, "Quality=high HRes=96 VRes=96")
'2) Foto verkleinen naar breedte = 213 en opslaan in 300dpi
graph.SetFile(strFullPath)
rect.String = graph(1).Rectangle
canvas.Clear()
canvas.Width = 213
canvas.Height = (213 * rect.Height) / rect.Width
canvas.DrawFile(strFullPath, "size=" & canvas.Width & "," & canvas.Height)
canvas.SaveAs(strFullPathNewLarge, "Quality=high HRes=300 VRes=300")
File.Delete(strFullPath) 'Delete upgeloade file
lblResults.Text = "Your file is uploaded.<br/>Due to webbrowser caching it's possible that you don't see your new uploaded picture. After hitting refresh (F5 for Internet Explorer) you should see your new uploaded picture.<br/>"
lblError.Text = ""
Else
lblError.Text = "Your file couldn't be uploaded for the following reason: Your file is not a .jpg, .bmp, .eps, .gif or .tif file."
lblResults.Text = ""
End If
Catch Ex As Exception
lblError.Text = "Your file couldn't be upload for the following reasen: " & Ex.Message
lblResults.Text = ""
Finally
'Refresh gridview
GridView1.DataBind()
End Try
Else
lblError.Text = "Please select first a student."
lblResults.Text = ""
End If
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
'Check if file exists
Dim strFile As String = "E:\Websites\ryedb.uploads\images\" 'Standaard path
Dim photo As System.Web.UI.WebControls.Image
If e.Row.RowType = DataControlRowType.DataRow Then
'Path aanvullen
strFile = strFile & DataBinder.Eval(e.Row.DataItem, "Foto").ToString
'Controleren of foto bestaat
If File.Exists(strFile) Then
'File exists => niets aanpassen
Else
'File doesn't exists => toon "unavailable" foto
photo = CType(e.Row.FindControl("Foto"), System.Web.UI.WebControls.Image)
photo.ImageUrl = "http://www.ryedb.net/files/images/unavailable.jpg"
End If
End If
End Sub
ASKER
Sorry I've forgot page load code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
End Sub
If File.Exists(strFile) Then
'File exists => niets aanpassen
Else
'File doesn't exists => toon "unavailable" foto
photo = CType(e.Row.FindControl("F oto"), System.Web.UI.WebControls. Image)
photo.ImageUrl = "http://www.ryedb.net/files/images/unavailable.jpg"
End If
if file exists what will happen?? show pictures over there ... I hope strFile contains latest image path!!
'File exists => niets aanpassen
Else
'File doesn't exists => toon "unavailable" foto
photo = CType(e.Row.FindControl("F
photo.ImageUrl = "http://www.ryedb.net/files/images/unavailable.jpg"
End If
if file exists what will happen?? show pictures over there ... I hope strFile contains latest image path!!
ASKER
If file exists then nothing should be changed and then is it the template field:
<asp:TemplateField HeaderText="Picture">
<ItemTemplate>
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") %>' />
</ItemTemplate>
</asp:TemplateField>
Eval("Foto") gives me the full url to the file (same as strFile but in stead of E:\websites ... it returns the "http path".
The file path is "District" & "_in_" & "id of the student" & "s" (small) + ".jpg" as it is saved with "strFullPathNewSmall" in the upload click button.
When a picture already exists and it is uploaded again, it overwrites the old one on the server, but when I display it it still gives me the old one, untill I hit F5 in my brower.
<asp:TemplateField HeaderText="Picture">
<ItemTemplate>
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") %>' />
</ItemTemplate>
</asp:TemplateField>
Eval("Foto") gives me the full url to the file (same as strFile but in stead of E:\websites ... it returns the "http path".
The file path is "District" & "_in_" & "id of the student" & "s" (small) + ".jpg" as it is saved with "strFullPathNewSmall" in the upload click button.
When a picture already exists and it is uploaded again, it overwrites the old one on the server, but when I display it it still gives me the old one, untill I hit F5 in my brower.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") & "?id=" & DateTime.Now.Minute.ToStri ng()&DateT ime.Now.Mi llisecond. ToString() %>' />
What I meant is that you should pass defferent values as query string eventhough we dont want any ! it avoid Caching
What I meant is that you should pass defferent values as query string eventhough we dont want any ! it avoid Caching
yes renjurdevan has a point here.
Calling any file after passing some random value as a querystring parameter causes to load that file uniquely.
so u can say that
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") & "?id=" & Guid.NewGuid %>' />
i passed guid here because it is returns a unique number always.
Calling any file after passing some random value as a querystring parameter causes to load that file uniquely.
so u can say that
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") & "?id=" & Guid.NewGuid %>' />
i passed guid here because it is returns a unique number always.
ooh sorry renjurdevan, it really looks like that i copied your point but i was in progress of writing when u posted the second comment.
ASKER
Thanks, great post. Works perfect.
ASKER
Thanks both for your answers. I've tried it and it works. I give the points to renjurdevan because his answer was the first one.
Add following snippen it Page_Load
Response.Cache.SetCacheabi