save add and other progress events with asp

Apr 15, 2010 at 8:06 PM

The project I am working on is using ASP2.0 , The web page allows users to choose files and then upload them. After the files are uploaded they are added to a zip file then saved on a file server for storage.  I have everthing working the way it should, files are uploaded , added to a zip then saved to a file server.  The users are shown a progress bar while all of this is taking place. The progress bar as of now shows the upload progress but not the zipping progress.  Im not quite sure what I will show in the progress bar for zipping as of yet (bytes saved or files saved or what ever will let the user know that something is happening). My problem is is that I have no clue as to how to set a variable to something such as  ZipProgressEventArgs.TotalBytesToTransfer  . So that I have something to reference the actual progress against. So maybe this is more of a VB syntax question. I have looked over the examples in the help file and cannot figure out how to access these attributes.  Thanks  in advance for the help.

Coordinator
Apr 21, 2010 at 4:13 PM

When you say "ASP2.0" , do you mean ASP.NET ?

I don't know what you mean by "I have no clue as to how to set a variable to something such as  ZipProgressEventArgs.TotalBytesToTransfer".

TotalBytesToTransfer is a long, System.Int64.  To assign a variable, the value contained in that field, you just do this:

 Dim variable as Int64 = e.TotalBytesToTransfer

 

Apr 21, 2010 at 5:21 PM

Cheeso,

        Hey thanks for the reply . Yes I do mean ASP.Net ... as far as how to assign a variable I undestand how to do that. I am just not sure how to get the value of ZipProgressEventArgs.TotalBytesToTranfer into a variable. It throws Object reference not set to an instance of an object error. Here is my error sample code

 

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles

using zip as New ZipFile()

zip.Name = zipfilename

zip.AddItem(filetozip)

dim zipevents as ZipProgressEventArgs

dim zipTotal_Bytes as zipevents.TotalBytesToTransfer

zip.Save(zipfilepath & zip.Name)

End Sub

 

 

 

<font face="Consolas" size="2" color="#0000ff">

 

</font>

Button1.Click

Coordinator
Apr 21, 2010 at 9:35 PM

Right, ok.   I think this is a misunderstanding of VB syntax and how to use the library.

The ZipProgressEventArgs is a type.

By using "dim zipevents as ZipProgressEventArgs" in your code, you are defining a variable named zipevents and tell the compiler that it is of a particular type (ZipProgressEventArgs).  You don't assign a value, which means the variable has a value of Nothing.   You're getting an exception by referencing a field in that object, because the object is Nothing.

What you need to do is define a progress event.  The way events work in .NET in general,  is the way DotNetZip uses them.  The method you call, ZipFile.Save(), will invoke YOUR code with progress updates, at various times as the save proceeds.  You need to provide a method, for ZipFile.Save() to call.    That method is of type EventHandler(Of ZipProgressEventArgs).  And you need to provide it by setting the ZipFile.SaveProgress property.

See http://cheeso.members.winisp.net/DotNetZipHelp/html/2b8624b0-6823-7e33-a864-2c7bbd9835e7.htm 

There's VB code on that documentation page.

Now, you're using ASPNET, so I'm not sure how you will communicate that progress back to the requesting client browser.  I don't know how the progressbar works with ASPNET, but I think it uses jQuery.  And my understanding is the jQuery progressbar needs to poll to the server to request progress updates. Therefore your code would have to stash the progress in its SaveProgress event, and then provide that stashed value if it receives a request for progress update from the browser.  A little complicated.

And... depending on the size of the zip file, and the stream you save into, this save may be very quick.  If you are saving to the filesystem, the save might take 2 seconds, even for a fairly large file.  So, consider whether you're sure you want the progress bar on the browser side to indicate save progress on the server side.  The communication overhead alone may dwarf the time required to simply save the zip file, if you see what I mean.

 

 

Apr 22, 2010 at 8:30 PM

Worked like a charm cheeso!!. Im using a custom progress bar to show the progress on the web page. I just plugged in e.bytestransferred and e.totalbytestransfered to its properties and it works without a hitch. I know that it may slow it down a bit to show the progress to the end user but I dont want people leaving the page thinking that there is an error because that will cause problems with other things that happen after the files are zipped.  Thanks again for the explanation for this .

 

 

Coordinator
Apr 23, 2010 at 10:33 PM

Sweet!  glad it worked for you.