Click here to Skip to main content
15,891,316 members
Articles / Web Development / ASP.NET

Multiple Fileupload for ASP.NET with Client Side Resizing of Images

Rate me:
Please Sign up or sign in to vote.
4.73/5 (15 votes)
13 Aug 2011CPOL3 min read 87.9K   5.7K   59  
Using plupload control in ASP.NET to upload multiple image files with client side resizing
Public Class upload
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsNothing(Request.Form("chunk")) = False Then
            If Session("ID") Is Nothing Then
                Session("ID") = Guid.NewGuid.ToString
                IO.Directory.CreateDirectory(Server.MapPath("Uploads/" & Session("ID")))
            End If
            Dim chunk As Integer = Request.Form("chunk")
            Dim chunks As Integer = Request.Form("chunks")
            Dim filename As String = Request.Form("name")
            If chunk = 0 Then
                Request.Files(0).SaveAs(Server.MapPath("Uploads/") & Session("ID") & "/" & Request.Files(0).FileName)
            Else
                Dim OutputStream As New IO.FileStream(Server.MapPath("Uploads/") & Session("ID") & "/" & Request.Files(0).FileName, IO.FileMode.Append)
                Dim InputBytes(Request.Files(0).ContentLength) As Byte
                Request.Files(0).InputStream.Read(InputBytes, 0, Request.Files(0).ContentLength)
                OutputStream.Write(InputBytes, 0, InputBytes.Length - 1)
                OutputStream.Close()
            End If
        End If
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
Pakistan Pakistan
A VB.NET MVP currently living and working in UK.

Comments and Discussions