Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a simple upload image code,It does not works when I click on the Upload button.So when I restart my program and see what that image is uploaded whats happening here,There may be post back issue or caching,so what should I do,I have use this ASP Syntax
ASP.NET
<asp:FileUpload ID="fuImage" Width="320" EnableTheming=true runat="server"  Visible="true" />  <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><asp:Button runat="server" ID="btnUploadImage" OnClick="UploadImage" Text="Upload Facility Image" Visible="true" ></asp:Button></font>
           </td>

C#
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"

                    fuImage.DataBind()

                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
        End Try

    End Sub
Posted
Updated 28-Feb-12 5:22am
v3
Comments
ZurdoDev 28-Feb-12 10:19am    
Your question does not make sense. You say the code works but the problem is it does not upload image. Please restate your question more clearly.
M Ali Qadir 28-Feb-12 10:26am    
I have updated it please guide me thank you.
Herman<T>.Instance 28-Feb-12 10:41am    
maybe add vb.net code and all asp code
M Ali Qadir 28-Feb-12 11:23am    
I have updated Question with Asp.Net and Vb.Net code,please have looks and tell me whats wrong where in the code.
thatraja 28-Feb-12 12:07pm    
what's the error message?

1 solution

Yes It Was a Matter of Page refresh So I added this line into the Aspx page And As page refresh Image loads.
Thank you.
<meta http-equiv="Refresh" content="10" />
 
Share this answer
 

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