Also note I know how to get to the CSV File part but don't know how to take that file and Zip it without creating it on a clients computer and reading it in and Zipping it.
But this Zip file must be created and zipped on the webserver and then Zip file can be downloaded as an attachment.
A little more context to the situation. What I'm basically doing is creating a CSV file from a select statement from a database but only when the user clicks on a button on the ASP page.
Here's the code I use to just make a csv file.
Note: In this code there is no MemoryStream, but I do know how to create a CSV that way.
Expand|Select|Wrap|Line Numbers
- try
- {
- GetSqlData(); //get sql data for the csv.
- HttpContext context = HttpContext.Current;
- context.Response.Clear();
- foreach (DataColumn column in FullDT.Columns)
- {
- context.Response.Write(column.ColumnName.ToString() + ",");
- }
- context.Response.Write(Environment.NewLine);
- foreach (DataRow row in FullDT.Rows)
- {
- for (int i = 0; i < row.ItemArray.Length; i++)
- {
- string rowText = row.ItemArray[i].ToString();
- if (rowText.Contains(","))
- {
- rowText = rowText.Replace(",", "/");
- }
- context.Response.Write(rowText + ",");
- }
- context.Response.Write(Environment.NewLine);
- }
- context.Response.ContentType = "text/csv";
- context.Response.AppendHeader("Content-Disposition", "attachment; filename="+ OutputFileName +".csv");
- context.Response.End();
- }
- catch (Exception ex)
- {
- Debug.WriteLine("Can Not Generate CSV File");
- throw ex;
- }
Thanks,
Yoda.