Can zip it before download?

A

ad

I use the code below to export the content of a data set to Excel, the code
come form
http://www.dotnetjohn.com/articles.aspx?articleid=36

It will take a long time to dolwnload if the excel file if too big.
How can I zip the excel file before download?

----------------------------------------------------------------------------
---------------
'first let's clean up the response.object
response.Clear()
response.Charset = ""
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'create a string writer
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
'instantiate a datagrid
Dim dg As New System.Web.UI.WebControls.DataGrid
'set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables(0)
'bind the datagrid
dg.DataBind()
'tell the datagrid to render itself to our htmltextwriter
dg.RenderControl(htmlWrite)
'all that's left is to output the html
response.Write(stringWrite.ToString)
response.End()
 
M

Mark Fitzpatrick

You sure can, you just need another component to do it. Check out shaprzip
(http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx). It enables
you to create a zip file and also to create and add files right into the new
zip. You can stream the new zip file to the browser just as you would an
excel file. Of course your users will have to unzip the file before they can
open the excel file, but most users will rather have a smaller, faster
download than be upset over having to open a zip file.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
A

ad

Thanks,
I have download the shaprzip, it say that scharzip must be built with nant.
I download the source code of nant, but I don't know how to complie it(I
can't find any doc about it)
Can some one help me again?
 
P

Pete

ad said:
Thanks,
I have download the shaprzip, it say that scharzip must be built with nant.
I download the source code of nant, but I don't know how to complie it(I
can't find any doc about it)
Can some one help me again?

Well the nant download has a folder called doc, and under that help.
Goto index.html, for instuctions on installation etc.

Although, my installation failed at a couple of different points, as
it wasn't picking up my latest 1.1 .net directories properly and I
couldn't figure it out. So I gave up. No zip for me.

I only wish .net components and user controls were as easy to install
as Delphi ones.
 
A

AlexL [Xceed]

Thanks,
I have download the shaprzip, it say that scharzip must be built with nant.
I download the source code of nant, but I don't know how to complie it(I
can't find any doc about it)
Can some one help me again?
Mark Fitzpatrick said:
[snip]
Of course your users will have to unzip the file before they
can open the excel file, but most users will rather have a smaller, faster
download than be upset over having to open a zip file.

Another thing you could do is to create a Self-Extracting Zip file for
your Excel file, which will not only reduce the size, but will unzip
itself (in case end-user does not have WinZip), display a custom
introduction message with any instructions you would like to give
about your Excel file, unzips the excel file where you want it, and
you can even put a password in case the Excel file falls into the
wrong hands, etc.

Xceed Zip for .NET can do this. (In only a few lines of code. And it
comes precompiled, easy to install, and fully documented.)

http://www.xceedsoft.com/products/zipnet




--
Alex Leblanc
Xceed Software Inc.
http://www.xceedsoft.com

Check out our advanced .NET grid and SmartUI controls

Email: (e-mail address removed) (remove the first 'x')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top