[
  {
    "Id": "1011985",
    "ThreadId": "435808",
    "Html": "I NEED HELP using dotnetzip and VB!\r<br />\n<br />\nI need to separate the files to download and zip into four categories that are listed separately but the user will be able to select files from all categories for download. (I just want one download button instead of four).\r<br />\n<br />\nHere's a link to my attempt to get this working: <a href=\"http://www.healthequity.com/NewSalesTest/checkbox/test4.aspx\" rel=\"nofollow\">http://www.healthequity.com/NewSalesTest/checkbox/test4.aspx</a>\r<br />\n<br />\nFor simplicity and since I'm a newbie, I'm trying to work out the kinks with just two categories. My code is below:\r<br />\n<br />\nDim width as String = &quot;100%&quot;\r<br />\nPublic Sub Page_Load (ByVal sender As Object, ByVal e As System.EventArgs)<br />\n<pre><code>Try\n    If Not ( Page.IsPostBack ) Then\n        ' populate the dropdownlist\n                    Dim hsaPath as  String= Server.MapPath(&quot;docs/hsa&quot;)\n        Dim hraPath as  String= Server.MapPath(&quot;docs/hra&quot;)\n\n                    Dim hsaFilenames As New List(Of String)(System.IO.Directory.GetFiles(hsaPath))\n        Dim hraFilenames As New List(Of String)(System.IO.Directory.GetFiles(hraPath))\n\n\n        Dim hsaDocs as List(Of String) = _\n            hsaFilenames.ConvertAll (Function(s) s.Replace(hsaPath &amp; &quot;\\&quot;, &quot;&quot;))\n\n        Dim hraDocs as List(Of String) = _\n            hraFilenames.ConvertAll (Function(s) s.Replace(hraPath &amp; &quot;\\&quot;, &quot;&quot;))\n\n        ErrorMessage.InnerHtml = &quot;&quot;\n\n        hsaFileListView.DataSource = hsaDocs\n        hraFileListView.DataSource = hraDocs\n        hsaFileListView.DataBind()\n        hraFileListView.DataBind()\n    End If\n\nCatch\n    ' Ignored\nEnd Try\n</code></pre>\n\nEnd Sub\r<br />\n<br />\n<br />\n<br />\nPublic Sub btnGo_Click (ByVal sender As System.Object, ByVal e As System.EventArgs)<br />\n<pre><code>ErrorMessage.InnerHtml =&quot;&quot;   ' debugging only\n\nDim HSAfilesToInclude as New System.Collections.Generic.List(Of String)()\nDim HRAfilesToInclude as New System.Collections.Generic.List(Of String)()\n\nDim hsaPath as String= Server.MapPath(&quot;docs/hsa&quot;)\nDim hraPath as String= Server.MapPath(&quot;docs/hra&quot;)\n\nDim HSAsource As DataKeyArray= hsaFileListView.DataKeys\nDim HRAsource As DataKeyArray= hraFileListView.DataKeys\n</code></pre>\n\nFor Each item As ListViewDataItem in hsaFileListView.Items<br />\n<pre><code>    Dim chkbox As CheckBox= CType(item.FindControl(&quot;HSAinclude&quot;), CheckBox)\n    Dim lbl As Label = CType(item.FindControl(&quot;HSAlabel&quot;), Label)\n\n    If Not (chkbox Is Nothing  OR  lbl Is Nothing) Then\n        If (chkbox.Checked) Then\n            ErrorMessage.InnerHtml = ErrorMessage.InnerHtml &amp; _\n                   String.Format(&quot;adding file: {0}&lt;br/&gt;&quot;, lbl.Text)\n            HSAfilesToInclude.Add(System.IO.Path.Combine(hsaPath,lbl.Text))\n            'filesToInclude.Concat(HSAfilesToInclude)\n        End If\n    End If\nNext\n\nFor Each item As ListViewDataItem in hraFileListView.Items\n\n   Dim chkbox As CheckBox= CType(item.FindControl(&quot;HRAinclude&quot;), CheckBox)\n   Dim lbl As Label = CType(item.FindControl(&quot;HRAlabel&quot;), Label)\n\n    If Not (chkbox Is Nothing  OR  lbl Is Nothing) Then\n        If (chkbox.Checked) Then\n            ErrorMessage.InnerHtml = ErrorMessage.InnerHtml &amp; _\n                    String.Format(&quot;adding file: {0}&lt;br/&gt;&quot;, lbl.Text)\n            HRAfilesToInclude.Add(System.IO.Path.Combine(hraPath,lbl.Text))\n            'filesToInclude.Concat(HRAfilesToInclude)\n        End If\n   End If\nNext\n\nDim filesToInclude as New System.Collections.Generic.List(Of String)()\nfilesToInclude.Concat(HSAfilesToInclude)\nfilesToInclude.Concat(HRAfilesToInclude)\n\n If (filesToInclude.Count=0) Then\n    ErrorMessage.InnerHtml = ErrorMessage.InnerHtml &amp; &quot;You did not select any files!&quot;\nElse\n    Response.Clear\n    Response.BufferOutput= false\n\n    Dim c As System.Web.HttpContext = System.Web.HttpContext.Current\n    Dim ReadmeText As String= String.Format(&quot;README.TXT\\n\\nHello!\\n\\n&quot; &amp; _\n                                     &quot;This is a zip file that was dynamically generated at {0}\\n&quot; &amp; _\n                                     &quot;by an ASP.NET Page running on the machine named '{1}'.\\n&quot; &amp; _\n                                     &quot;The server type is: {2}\\n&quot; &amp; _\n                                     System.DateTime.Now.ToString(&quot;G&quot;), _\n                                     System.Environment.MachineName, _\n                                     c.Request.ServerVariables(&quot;SERVER_SOFTWARE&quot;))\n    Dim archiveName as String= String.Format(&quot;archive-{0}.zip&quot;, DateTime.Now.ToString(&quot;yyyy-MMM-dd-HHmmss&quot;))\n    Response.ContentType = &quot;application/zip&quot;\n    Response.AddHeader(&quot;Content-Disposition&quot;, &quot;inline; filename=&quot; &amp; chr(34) &amp; archiveName &amp; chr(34))\n\n    Dim tempfile As String = &quot;c:\\temp\\&quot; &amp; archiveName\n    Using zip as new ZipFile()\n        ' the Readme.txt file will not be password-protected.\n        zip.AddEntry(&quot;Readme.txt&quot;, ReadmeText, Encoding.Default)\n\n        ' filesToInclude is a string[] or List&lt;String&gt;\n        zip.AddFiles(filesToInclude, &quot;files&quot;)\n\n        ' save the zip to a filesystem file\n        zip.Save(tempfile)\n    End Using\n\n    ' open and read the file, and copy it to Response.OutputStream\n    Using fs as System.IO.FileStream = System.IO.File.OpenRead(&quot;c:\\temp\\&quot; &amp; archiveName)\n        dim b(1024) as Byte\n        dim n as New Int32\n        n=-1\n        While (n &lt;&gt; 0)\n            n = fs.Read(b,0,b.Length)\n            If (n &lt;&gt; 0)\n                Response.OutputStream.Write(b,0,n)\n            End If\n        End While\n    End Using\n    Response.Close\n    System.IO.File.Delete(tempfile)\n\nEnd If\n</code></pre>\n\nEnd Sub\r<br />\n<br />\n<br />\n&lt;/script&gt;\r<br />\n<br />\n<br />\n<br />\n&lt;html&gt;<br />\n&lt;head&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style/basic.css&quot;&gt;\r\n  &lt;/head&gt;\r\n&lt;body&gt;<br />\n<pre><code>&lt;form id=&quot;Form&quot; runat=&quot;server&quot;&gt;\n\n  &lt;span class=&quot;SampleTitle&quot;&gt;&lt;b&gt;Check the boxes to select the files, set a password if you like, then click the button to zip them up.&lt;/b&gt;&lt;/span&gt;\n  &lt;br/&gt;\n  &lt;br/&gt;\n  &lt;span style=&quot;color:red&quot; id=&quot;ErrorMessage&quot; runat=&quot;server&quot;/&gt;\n  &lt;br/&gt;\n&lt;h2&gt;HSA&lt;/h2&gt;\n  &lt;asp:ListView ID=&quot;hsaFileListView&quot; runat=&quot;server&quot;&gt;\n\n    &lt;LayoutTemplate&gt;\n      &lt;table&gt;\n        &lt;tr ID=&quot;itemPlaceholder&quot; runat=&quot;server&quot; /&gt;\n      &lt;/table&gt;\n    &lt;/LayoutTemplate&gt;\n\n    &lt;ItemTemplate&gt;\n      &lt;tr&gt;\n        &lt;td&gt;&lt;asp:Checkbox ID=&quot;HSAinclude&quot; runat=&quot;server&quot;/&gt;&lt;/td&gt;\n        &lt;td&gt;&lt;asp:Label id=&quot;HSAlabel&quot; runat=&quot;server&quot; Text=&quot;&lt;%# Container.DataItem %&gt;&quot; /&gt;&lt;/td&gt;\n      &lt;/tr&gt;\n    &lt;/ItemTemplate&gt;\n\n    &lt;EmptyDataTemplate&gt;\n      &lt;div&gt;Nothing to see here...&lt;/div&gt;\n    &lt;/EmptyDataTemplate&gt;\n\n  &lt;/asp:ListView&gt;\n&lt;h2&gt;HRA&lt;/h2&gt; \n  &lt;asp:ListView ID=&quot;hraFileListView&quot; runat=&quot;server&quot;&gt;\n\n    &lt;LayoutTemplate&gt;\n      &lt;table&gt;\n        &lt;tr ID=&quot;itemPlaceholder&quot; runat=&quot;server&quot; /&gt;\n      &lt;/table&gt;\n    &lt;/LayoutTemplate&gt;\n\n    &lt;ItemTemplate&gt;\n      &lt;tr&gt;\n        &lt;td&gt;&lt;asp:Checkbox ID=&quot;HRAinclude&quot; runat=&quot;server&quot;/&gt;&lt;/td&gt;\n        &lt;td&gt;&lt;asp:Label id=&quot;HRAlabel&quot; runat=&quot;server&quot; Text=&quot;&lt;%# Container.DataItem %&gt;&quot; /&gt;&lt;/td&gt;\n      &lt;/tr&gt;\n    &lt;/ItemTemplate&gt;\n\n    &lt;EmptyDataTemplate&gt;\n      &lt;div&gt;Nothing to see here...&lt;/div&gt;\n    &lt;/EmptyDataTemplate&gt;\n\n  &lt;/asp:ListView&gt;\n\n    &lt;br/&gt;\n    &lt;br/&gt;\n    &lt;asp:Button id=&quot;btnGo&quot; Text=&quot;Zip checked files&quot; AutoPostBack OnClick=&quot;btnGo_Click&quot; runat=&quot;server&quot;/&gt;\n\n&lt;/form&gt;\n</code></pre>\n\n&lt;/body&gt;\r<br />\n<br />\n&lt;/html&gt;<br />\n",
    "PostedDate": "2013-03-07T12:43:57.983-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]