0

i used this code to upload the images from the local path. but when i'm trying to upload the images in the webpage it is not showing. can any one can tell what's wrong in the coding. it will be very helpful.........................

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        ImageMap1.AlternateText = ""
        If FileUpload1.HasFile Then
            Try
                If (FileUpload1.PostedFile.FileName.EndsWith(".jpg")) Then
                    FileUpload1.SaveAs("C\Documents and Settings" & _FileUpload1.FileName)
                    ImageMap1.AlternateText = "uploaded sucessfully....." & "<br>" & "File name: " & _
                           FileUpload1.PostedFile.FileName & "<br>" & _
                           "File Size: " & _
                           FileUpload1.PostedFile.ContentLength & " kb<br>" '& 
                Else
                    ImageMap1.AlternateText = "Not a valid file."
                End If
            Catch ex As Exception
                ImageMap1.AlternateText = "ERROR: " & ex.Message.ToString()
            End Try
        Else
            ImageMap1.AlternateText = "You have not specified a file."
        End If
    End Sub

please help me... need it very urgently.
thanks a lot

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by pauldani
0

Try to save image or any uploaded file into sub-folder under your webapplication root.

For example,

IF FileUpload1.FileBytes.Length<>0 Then   
   Dim target as String ="~/images/" & FileUpload1.FileName
   FileUpload1.SaveAs(MapPath(target))
   Image1.ImageUrl=target
End If
0

this is the code for uploading images.....................................................

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        If FileUpload1.HasFile Then
            Try
                If (FileUpload1.PostedFile.FileName.EndsWith(".jpg")) Then
                    If FileUpload1.FileBytes.Length <> 0 Then
                        Dim target As String = "~/pictures/" & FileUpload1.FileName
                        FileUpload1.SaveAs(MapPath(target))
                        Image1.ImageUrl = target
                    End If

                Else
                End If
            Catch ex As Exception

            End Try
        Else

        End If
    End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.