Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Expert advice needed!

Reply
Thread Tools

Expert advice needed!

 
 
Smith
Guest
Posts: n/a
 
      11-09-2007
Hello,
My code below create a .CSV file and compress it with the new GZipStream
class.

My problem, is how to set the extension of the uncompressed file to .csv.
Users have to manually do this and it is not quite convenient. Any help will
be highly appreciated.

File: handler.ashx:
public void ProcessRequest(HttpContext context)

{



HttpResponse Response = context.Response;

HttpRequest Request = context.Request;


Response.Clear();

Response.Buffer = true;


//Using a new compression class of the framework

GZipStream gzStream = new GZipStream(Response.OutputStream,
CompressionMode.Compress);

StreamWriter sw = new StreamWriter(gzStream);

DataTable dt = Session["MyDataTable"];

if (dt != null)

{

int iColCount = dt.Columns.Count;

for (int i = 0; i < iColCount; i++)

{

sw.Write(dt.Columns[i]);

if (i < iColCount - 1)

{

sw.Write(",");

}

}

sw.Write(sw.NewLine);

// Now write all the rows.

foreach (DataRow dr in dt.Rows)

{

for (int i = 0; i < iColCount; i++)

{

if (!Convert.IsDBNull(dr[i]))

{

sw.Write(dr[i].ToString().Trim());

}

if (i < iColCount - 1)

{

sw.Write(",");

}

}

sw.Write(sw.NewLine);

}

sw.Close();

Response.ContentType = "application/x-Gzip";

Response.AddHeader("content-disposition", "attachment; filename=" +
"compressed_file.gz");


Response.End();

}

}



S


 
Reply With Quote
 
 
 
 
Barrie Wilson
Guest
Posts: n/a
 
      11-09-2007

"Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> My code below create a .CSV file and compress it with the new GZipStream
> class.
>
> My problem, is how to set the extension of the uncompressed file to .csv.
> Users have to manually do this and it is not quite convenient. Any help
> will be highly appreciated.



here's a discussion of your issue:

http://msdn.microsoft.com/msdnmag/is...10/NETMatters/




 
Reply With Quote
 
 
 
 
Smith
Guest
Posts: n/a
 
      11-09-2007
>
> http://msdn.microsoft.com/msdnmag/is...10/NETMatters/


Hello Barrie Wilson,

Thank you for the link. This seems to be the only online resource i have
come accross that addresses this matter.

Cheers
S


 
Reply With Quote
 
Smith
Guest
Posts: n/a
 
      11-09-2007
>
> here's a discussion of your issue:
>
> http://msdn.microsoft.com/msdnmag/is...10/NETMatters/
>


The more i got into this, the more i see that it does not solve my problem
anyway. This solution seems only to apply to file system files. I do not
have a file on disk. I have my data in memory in a data table.

Any furthere thoughts?

Thanks
Smith


 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      11-09-2007
"Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> The more i got into this, the more i see that it does not solve my problem
> anyway. This solution seems only to apply to file system files. I do not
> have a file on disk. I have my data in memory in a data table.


I use the Chilkat Zip component for this type of thing.

It has a method specifically designed to solve your particular problem:
http://www.chilkatsoft.com/refdoc/cs...html#method033

Incidentally, it also has full GZip support, though you don't need that in
this instance...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need expert advice on parsing a string into java beans Edmond wong Java 1 04-25-2005 06:31 AM
I need this groups expert advice. PIPER Computer Support 10 09-22-2004 05:42 AM
Help: SHA-1 problem, requires some expert advice. FISH Java 4 07-20-2004 04:34 PM
Advice from an expert needed! AndyŻ MCSE 4 03-01-2004 11:21 PM
Expert advice needed John Smith C++ 7 08-18-2003 10:54 AM



Advertisments