[
  {
    "Id": "180273",
    "ThreadId": "53558",
    "Html": "Hi All<br>\r\n<br>\r\nPlease assist a newbie!!<br>\r\n<br>\r\nI have a web app that generates a .csv file dynamically and on the fly and sends it to the user to either open or save.<br>\r\n<br>\r\nI would like to use the DotNetZip library to zip the file before sending it downstreem to the client.<br>\r\nMy current code is as follows:<br>\r\nusing System;<br>\r\nusing System.Collections.Generic;<br>\r\nusing System.Data;<br>\r\nusing System.Linq;<br>\r\nusing System.Web;<br>\r\nusing System.Web.UI;<br>\r\nusing System.Web.UI.WebControls;<br>\r\nusing DashBoardTableAdapters;<br>\r\nusing Ionic.Zip;\r\n<p>public partial class Sample1 : System.Web.UI.Page<br>\r\n{<br>\r\n int clientid = 0;<br>\r\n string usergroup = &quot;false&quot;;<br>\r\n protected void Page_Load(object sender, EventArgs e)<br>\r\n {<br>\r\n  if (this.Request[&quot;c&quot;] != null)<br>\r\n  {<br>\r\n   if (this.Request[&quot;c&quot;] != &quot;&quot;)<br>\r\n   {<br>\r\n    clientid = Convert.ToInt32(this.Request[&quot;c&quot;].ToString());<br>\r\n   }<br>\r\n  }<br>\r\nif (this.Request[&quot;ug&quot;] != null)<br>\r\n  {<br>\r\n   if (this.Request[&quot;ug&quot;] != &quot;&quot;)<br>\r\n   {<br>\r\n    usergroup = this.Request[&quot;ug&quot;].ToString();<br>\r\n   }<br>\r\n  }<br>\r\n  if (usergroup == &quot;false&quot;)<br>\r\n  {<br>\r\n   btnExport.Text = &quot;Export Master Data to MasterData_&quot; + clientid + &quot;.csv&quot;;<br>\r\n  }<br>\r\n  else<br>\r\n  {<br>\r\n   btnExport.Text = &quot;Export Master Data to MasterData_&quot; + clientid + &quot;_&quot; + usergroup + &quot;.csv&quot;;<br>\r\n  }<br>\r\n }<br>\r\n protected void btnExport_Click(object sender, EventArgs e)<br>\r\n {<br>\r\n  if (usergroup == &quot;false&quot;)<br>\r\n  {<br>\r\n   ExportCSV(CreateData(), &quot;MasterData_&quot; + clientid);<br>\r\n  }<br>\r\n  else<br>\r\n  {<br>\r\n   ExportCSV(CreateData(), &quot;MasterData_&quot; + clientid + &quot;_&quot; + usergroup);<br>\r\n  }<br>\r\n }<br>\r\n public void ExportCSV(DataTable data, string fileName)<br>\r\n {<br>\r\n  HttpContext context = HttpContext.Current;<br>\r\n  context.Response.Clear();<br>\r\n  context.Response.ContentType = &quot;text/csv&quot;;<br>\r\n  context.Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + fileName + &quot;.csv&quot;);<br>\r\n  //write column header names<br>\r\n  for (int i = 0; i &lt; data.Columns.Count - 1; i++)<br>\r\n  {<br>\r\n   if (i &gt; 0)<br>\r\n   {<br>\r\n    context.Response.Write(&quot;,&quot;);<br>\r\n   }<br>\r\n   context.Response.Write(data.Columns[i].ColumnName);<br>\r\n  }<br>\r\n  context.Response.Write(Environment.NewLine);<br>\r\n  //Write data<br>\r\n  foreach (DataRow row in data.Rows)<br>\r\n  {<br>\r\n   for (int i = 0; i &lt; data.Columns.Count - 1; i++)<br>\r\n   {<br>\r\n    if (i &gt; 0)<br>\r\n    {<br>\r\n     context.Response.Write(&quot;,&quot;);<br>\r\n    }<br>\r\n    context.Response.Write(row.ItemArray[i].ToString());<br>\r\n   }<br>\r\n   context.Response.Write(Environment.NewLine);<br>\r\n  }<br>\r\n  context.Response.End();<br>\r\n }<br>\r\n private DataTable CreateData()<br>\r\n {<br>\r\n  MasterGridTableAdapter ta = new MasterGridTableAdapter();<br>\r\n  DataTable table1 = ta.GetMasterGrid(clientid, usergroup);<br>\r\n  return table1;<br>\r\n }<br>\r\n}<br>\r\n<br>\r\nWhere and how would I add the code to zip before sending to the client. Please help in as much detail as possible as I am new to dotnet.<br>\r\n<br>\r\nKind Regards.</p>\r\n",
    "PostedDate": "2009-04-16T13:17:29.237-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "180990",
    "ThreadId": "53558",
    "Html": "Here's an example of an ASP.NET page that zips up a file dynamically and downloads it to the browser: <br>\r\n<a href=\"http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET Example\">http://code.msdn.microsoft.com/DotNetZip/Wiki/View.aspx?title=ASP.NET%20Example</a><br>\r\n",
    "PostedDate": "2009-04-19T08:52:14.69-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]