Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have Vb code that Upload And displays Image,Problem is that when I try to upload image then it does not works,But when I Refresh page then Image is uploaded So please Let me know what is the Problem Is there any issue of caching or etc.
Thanks & Regards.


VB
Protected Sub UploadImage(ByVal sender As Object, ByVal e As EventArgs)
       Try
            Dim saveDir As String = ConfigurationManager.AppSettings.Item("BaseApplicationFolder")

           ' Get the physical file system path for the currently
           ' executing application.
           Dim appPath As String = Request.PhysicalApplicationPath
           If Not FACID = txtFacId.Text And Not String.IsNullOrEmpty(txtFacId.Text) Then
               FACID = txtFacId.Text
           End If
           ' Before attempting to save the file, verify
           ' that the FileUpload control contains a file.
           If (fuImage.HasFile) Then
               Dim savePath As String = appPath + "_images\assisted_living\fac_profile_pic\" + _
                   Server.HtmlEncode(fuImage.FileName)
                   If fuImage.FileName.Contains(FACID) Then

                   ' Call the SaveAs method to save the uploaded file to the specified path.
                   ' If a file with the same name already exists in the specified path, the uploaded file overwrites it.
                   If (File.Exists(savePath)) Then
                       File.Delete(savePath)

                   End If

                   fuImage.SaveAs(savePath)

                   Fac_picture.ImageUrl = "..\..\_images\assisted_living\fac_profile_pic\" + FACID + ".jpg"

                   Response.Cache.SetCacheability(HttpCacheability.NoCache)


               Else
                   lbl_message.Text = "The image name and facility name should match."
               End If

           End If
       Catch ex As Exception
           lbl_message.Text = ex.Message

       Finally
           Response.Redirect("UpdateFacilityProfile.aspx?FACID=" & FACID)
       End Try

   End Sub
Posted
Updated 29-Feb-12 6:42am
v2
Comments
ZurdoDev 29-Feb-12 11:21am    
From your description it IS uploading the image, so what do you mean? Are you saying it is not on the page until you refresh? If so, that is because the upload is asynchronous so the page is not entirely refreshed. You'll have to write code to refresh the part where the web page is. And if you shared some of your code we could help further.
M Ali Qadir 29-Feb-12 12:43pm    
I have this code Please have look and tell me how could I resolve this Issue.thank You
M Ali Qadir 29-Feb-12 13:11pm    
Would you reply me please its getting into an annoying problem me I have tried many method to load the image but same issue that image always load after the page refresh.what should I do. thank you.

1 solution

You need to elaborate your problem here. Is it matter of uploading the image i.e. saving on server or Showing in Image box.

As I know there is no straight way to upload an image through asynchronous/partial post back mode. Are you using Ajax? If yes, then image will not upload until you will not refresh the page.

Remove Ajax for file uploading or use some trick to upload it.
 
Share this answer
 
Comments
ZurdoDev 29-Feb-12 14:59pm    
Actually, the file upload control in the Ajax toolkit does do an asynch upload.
M Ali Qadir 1-Mar-12 5:59am    
Sir I am not using ajax And I am saving image on server,What kind Of tricks could be possible please elaborate thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900