Multiple File Upload w/ Compression

This is an extension of some great CSS which had no actual functionality other than a progress bar.

So I tapped into some previous uploaders I  had created and came up with this.

Compression was on the table so I threw that in too.



The C#

  private Boolean keepOriginal = true;

        private Boolean PerformUploadComplete()



            UploadDetail Upload = new UploadDetail { IsReady = false };


            //if request compression >>> Compress and return result


            if (Request[“remove”] != null && System.Convert.ToBoolean(Request[“remove”]))


                keepOriginal = false;



            //Let the webservie know that we are not yet ready

            // Upload.IsReady = false;

            if (Request.Files[0] != null && Request.Files[0].ContentLength > 0)



                string _creator = String.Empty;


                //build the local path where upload all the files

                string path = Server.MapPath(“~/PDF”);

                string fileName = Path.GetFileName(Request.Files[0].FileName);



                //Build the strucutre and stuff it into DTO

                Upload.Creator = _creator;

                Upload.ContentLength = Request.Files[0].ContentLength;

                Upload.FileName = fileName;

                Upload.UploadedLength = 0;

                //Let the polling process know that we are done initializing …

                Upload.IsReady = true;


                //set the buffer size to something larger.

                //the smaller the buffer the longer it will take to download,

                //but the more precise your progress bar will be.

                int bufferSize = 1;

                byte[] buffer = new byte[bufferSize];

                try {

                //Writing the byte to disk

                using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Create))


                    //As long was we haven’t written everything …

                    while (Upload.UploadedLength < Upload.ContentLength)


                        //Fill the buffer from the input stream

                        int bytes = Request.Files[0].InputStream.Read(buffer, 0, bufferSize);

                        //Writing the bytes to the file stream

                        fs.Write(buffer, 0, bytes);

                        //Update the number the webservice is polling on to the session

                        Upload.UploadedLength += bytes;




                if(IsCompressed(fileName, path)){ this.litScriptUpdate.Text = “// <![CDATA[
function(){  notify(‘”+ fileName + ” Compressed successfully’); }
// ]]>”; }


                catch (Exception exmsg)


                    return false;


              if (!keepOriginal) { DeleteFile(fileName, path); }


          return Upload.IsReady;


 The Bloody Html

<html xmlns=”“>

<head runat=”server”>




    <form id=”form” runat=”server” enctype=”multipart/form-data”>




        function notify(message) {

           // alert(message);


           jqXHR.creator.document.bgColor = ‘lightgreen’;



     <asp:Literal ID=”litScriptUpdate” runat=”server”></asp:Literal>




Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.