Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Image refresh file IO problem or cache or something else?

Posted on 2008-06-11
11
Medium Priority
?
363 Views
Last Modified: 2013-11-07
I've read the topic http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23066709.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
0
Comment
Question by:DataconsultGent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21758034
Disable cache !!

Add following snippen it Page_Load

Response.Cache.SetCacheability(HttpCacheability.NoCache)
0
 

Author Comment

by:DataconsultGent
ID: 21758142
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
    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

Open in new window

0
 

Author Comment

by:DataconsultGent
ID: 21758146
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

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 12

Expert Comment

by:renjurdevan
ID: 21758173
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


if file exists what will happen?? show pictures over there ... I hope strFile contains latest image path!!

 
0
 

Author Comment

by:DataconsultGent
ID: 21758265
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.
0
 
LVL 12

Accepted Solution

by:
renjurdevan earned 2000 total points
ID: 21758386
Try

    <asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") & "?id=" & DateTime.Now.MilleSecond.Tostring() %>' />
0
 
LVL 12

Expert Comment

by:renjurdevan
ID: 21758416
<asp:Image ID="Foto" runat="server" ImageUrl='<%# "http://www.ryedb.net/files/images/" & Eval("Foto") & "?id=" & DateTime.Now.Minute.ToString()&DateTime.Now.Millisecond.ToString()  %>' />

What I meant is that you should pass defferent values as query string eventhough we dont want any ! it avoid Caching  
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 21758435
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.
0
 
LVL 18

Expert Comment

by:Ajay Sharma
ID: 21758445
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.
0
 

Author Closing Comment

by:DataconsultGent
ID: 31466053
Thanks, great post.  Works perfect.
0
 

Author Comment

by:DataconsultGent
ID: 21758846
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question