vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, June 15, 2011

How to Upload Multiple Files at a time in ASP.Net?


Hi.
Here i am going to explain about to upload multiple files using asp.net.For this one they are following many methods.But this one would be very simple one to upload multiple files.

 You have to add 3 fileupload control from toolbox and add one button.Also create one saved path to save this file.This path you can create anywhere ,even if it inside project also your wish...
Add this code in Button Click Event..


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim filepath As String = "C:\Uploads"
        Dim uploadedFiles As HttpFileCollection = Request.Files

        For i As Integer = 0 To uploadedFiles.Count - 1
            Dim userPostedFile As HttpPostedFile = uploadedFiles(i)
            Try
                If userPostedFile.ContentLength > 0 Then
                    Label1.Text += "<u>File #" & (i + 1) & "</u><br>"
                    Label1.Text += "File Content Type: " & userPostedFile.ContentType & "<br>"
                    Label1.Text += "File Size: " & userPostedFile.ContentLength & "kb<br>"
                    Label1.Text += "File Name: " & userPostedFile.FileName & "<br>"

                    userPostedFile.SaveAs(filepath & "\" & System.IO.Path.GetFileName(userPostedFile.FileName))

                    Label1.Text += "Location where saved: " & filepath & "\" & System.IO.Path.GetFileName(userPostedFile.FileName) & "<p>"
                End If
            Catch Ex As Exception
                Label1.Text += "Error: <br>" & Ex.Message
            End Try
        Next
    End Sub

i hope this one helpful to you....

0 comments:

Post a Comment