Monday, 31 December 2012

multiple file upload in asp.net VB.NET

multiple file upload in asp.net  VB.NET


Step 1)  Create a Webpage name it as MultipleFileUploadsDemo

Step 2)  Add FileUpload Controls and 1 Button control
<div>
        <asp:FileUpload ID="FileUpload1" runat="server"  /><br />
        <asp:FileUpload ID="FileUpload2" runat="server" />
        <br />
        <br />
        <asp:Button ID="btnUpload2" runat="server" Text="Upload files" OnClick="btnUpload_Click"  /><br />
    </div>


Step 3) Create a uploads folder in WebApplication

Step 4) If Website  is in IIS Directory(for ex:C:\inetpub\wwwroot\Test\WebApplication1) ,make sure all access permissions set   for
IIS_IUSRS(machinename\IIS_USRS) user i.e read and write permissions for uploads folder
.

Step 5) If Website is file based, no need to worry about permissions

Step 6) Once it is done, Add Event Handler for btnUpload shown above

     protected void btnUploads_Click(Object sender, EventArgs e)
        {
                        Try

                if (FileUpload1.HasFile)
                {
                    Savefile(FileUpload1.FileContent, FileUpload1.FileName)
                }
                if (FileUpload2.HasFile)
                {
                    Savefile(FileUpload2.FileContent, FileUpload1.FileName)
                }

            Catch ex As Exception
                Response.Write(ex.Message)
                        End Try

        }

    void Savefile(System.IO.Stream stream, String fileName)
        {
            Imports (System.IO.StreamReader reader = New System.IO.StreamReader(stream))
            {
                Dim content As String =  reader.ReadToEnd()
                System.IO.File.AppendAllText(MapPath("./uploads/" fileName),content)
            }
        }


Tags:multiple file upload in asp.net , multiple file upload in asp.net 3.5/4.0,multiple file upload in asp.net using C#, multiple file upload in asp.net C#,multiple FileUpload in asp.net

No comments:

Post a Comment