Create ZipFile from a file list

Oct 9, 2009 at 2:02 AM
Edited Oct 9, 2009 at 2:07 AM

Hi Cheeso,

We'd  like to offer our customers a way to build a list of files they'd like to include in their own zip file - to be downloaded either right away ( from Disc or Response.OutputStream) or later - before their done browsing our site).

The way they'd be able to pick files is to go through the different GridViews I have (different pages within the same online app).  Each GridView has a checkbox column to indicate the file that they want to add.

Any ides on the way to approach this?

Thanks,

Doug

 

 

Coordinator
Oct 9, 2009 at 2:50 AM

Yes, there's an example you can download at http://dotnetzip.codeplex.com/Wiki/View.aspx?title=ASPNET%20Example%201&referringTitle=Home 

It looks like this:

It doesn't use a GridView -  it uses an ASPNET ListView with checkboxes.  But, same idea.

Oct 9, 2009 at 3:18 AM
Hey that's great!
Thanks Cheeso.
----- Original Message -----
From: [email removed]
To: [email removed]
Sent: Thursday, October 08, 2009 6:50 PM
Subject: Re: Create ZipFile from a file list [DotNetZip:71441]

From: Cheeso

Yes, there's an example you can download at http://dotnetzip.codeplex.com/Wiki/View.aspx?title=ASPNET%20Example%201&referringTitle=Home

It looks like this:

It doesn't use a GridView - it uses an ASPNET ListView with checkboxes. But, same idea.

Mar 1, 2010 at 12:38 PM

Hi.

I've searched for a way to select the files you want to add to zip, instead of choosing the whole folder, and I came up with the above example.

Since I already have a selection of files to download, with a date, description and name, what I am looking for, is a way to pick the requested files with a checkbox, instead of having it buily dinamically.

 

To make this simpler, I'll show a little portion:

	 <tr>
                <th width="8%" height="25px" align="center">
                    <b>Código</b>
                </th>
                <th width="57%" align="center">
                    <b>Designação</b>
                </th>
                <th width="17%" align="center">
                    <b>Disponibilizado em</b>
                </th>
                <th width="18%" align="center">
                    <b>Observações</b>
                </th>
     </tr>

     <tr >
		<td border="1" width="8%" align=center>
		<p ><input type="checkbox" name="option1" value="EncGlobal"><a href="docs/EncG90012010.zip">Encontro 9001</a></p>
		</td>

		<td border="1" width="57%" align=left>
  		<p >Encontro de Auditores ISO 9001 (2010)</p>
		</td>

		<td border="1" width="17%" align=center>
  		<p >02/10</p>
		</td>

		<td border="1" width="18%" align=center>
  		<p ><b>NOVO</b></p>
		</td>
  
	</tr>	

How can I retrieve the checkbox options for it to build the zip file?

 

Any help is very much appreciated

Coordinator
Mar 1, 2010 at 6:54 PM

> what I am looking for, is a way to pick the requested files with a checkbox, instead of having it buily dinamically.

I don't know what you mean.  The example I cited examines the checked items like this:

foreach (var item in  FileListView.Items)
{
    CheckBox chkbox= item.FindControl("include") as CheckBox ;
    Label lbl= item.FindControl("label") as Label ;

    if (chkbox!=null  && lbl != null)
    {
	if (chkbox.Checked)
	{
	    ErrorMessage.InnerHtml += String.Format("adding file: {0}<br/>\n", lbl.Text);
	    filesToInclude.Add(System.IO.Path.Combine(sMappedPath,lbl.Text));
	}
    }
}


Mar 1, 2010 at 7:05 PM

Let me try to explain this better.

 

Instead of the list of downloads available being built dinamically (reading from the folder, the files and then make each entry for each file), I want to be able to have the list of files in the html, just like the example of code that i posted.

         <tr >
		<td border="1" width="8%" align=center>
		<p ><input type="checkbox" name="option1" value="EncGlobal"><a href="docs/EncG90012010.zip">Encontro 9001</a></p>
		</td>

		<td border="1" width="57%" align=left>
  		<p >Encontro de Auditores ISO 9001 (2010)</p>
		</td>

		<td border="1" width="17%" align=center>
  		<p >02/10</p>
		</td>

		<td border="1" width="18%" align=center>
  		<p ><b>NOVO</b></p>
		</td>
  
	</tr>	

The checkbox on the above example was added by me, to better explain what I need. I have like a 100 files available on the asp page, just like that and I want to be able to click on the checkbox of each one, but i can't have that list coming from the list of files on the folder.

 

Coordinator
Mar 1, 2010 at 7:45 PM

ok, you want an HTML file with ~100 files, and you don't want that html to be generated dynamically. 

And you want a checkbox by each of those files.

That all seems easy.  I think you have that part covered.  What's the question?

 

Mar 1, 2010 at 9:19 PM

i get that

 

foreach (var item in  FileListView.Items)
{
    CheckBox chkbox= item.FindControl("include") as CheckBox ;
    Label lbl= item.FindControl("label") as Label ;

    if (chkbox!=null  && lbl != null)
    {
	if (chkbox.Checked)
	{
	    ErrorMessage.InnerHtml += String.Format("adding file: {0}<br/>\n", lbl.Text);
	    filesToInclude.Add(System.IO.Path.Combine(sMappedPath,lbl.Text));
	}
    }
}


will add the checked files to the zip from the filelistview, but i'm not going to use filelistview or listview right? so how do i make my checked files zipped?
that's what i want to know. how to adapat the above, to zip the files if i'm not populating the webpage dynamically.

Coordinator
Mar 1, 2010 at 9:26 PM
Edited Mar 1, 2010 at 9:26 PM

ok, yours is more of an ASPNET question.

Even if you're not populating dynamically, you can still have a FileListView control - statically created. 

But maybe you want to enumerate through all the checkboxes a different way.  Maybe you're choosing a different control to use.

Try searching for ASPNET example code.  http://www.bing.com/search?q=ASPNET+checkbox+state+form+submit+&form=QBRE&qs=n 

 

 

Mar 2, 2010 at 3:11 PM

I'm just not very good at this.

I can't seem to understand how will I add the files from the checked boxes to the zip.

Somewhere between

<asp:Checkbox ID="include" runat="server"/> on the list of files available and

Dim filesToInclude as New System.Collections.Generic.List(Of String)()
        Dim chkbox As CheckBox = CType(FindControl("include"), Check

Using zip As New ZipFile()
                
            zip.AddFiles()
            
            zip.Save(Response.OutputStream)

for the actual zip saving and downloading. Could you help me out?

 

Coordinator
Mar 2, 2010 at 4:35 PM

yes, go to any one of the first three links on this search: http://www.bing.com/search?q=asp.net+checkbox+example&FORM=QBHP

They are all examples of how to use the checkbox control in aspnet.