Expert advice needed!

Discussion in 'ASP .Net' started by Smith, Nov 9, 2007.

  1. Smith

    Smith Guest

    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);

    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))

    {

    sw.Write(dr.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
     
    Smith, Nov 9, 2007
    #1
    1. Advertising

  2. "Smith" <> wrote in message
    news:...
    > 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/issues/05/10/NETMatters/
     
    Barrie Wilson, Nov 9, 2007
    #2
    1. Advertising

  3. Smith

    Smith Guest

    Smith, Nov 9, 2007
    #3
  4. Smith

    Smith Guest

    >
    > here's a discussion of your issue:
    >
    > http://msdn.microsoft.com/msdnmag/issues/05/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
     
    Smith, Nov 9, 2007
    #4
  5. "Smith" <> wrote in message
    news:...

    > 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/csZipRef.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
     
    Mark Rae [MVP], Nov 9, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith

    Expert advice needed

    John Smith, Aug 16, 2003, in forum: C++
    Replies:
    7
    Views:
    540
    Ahti Legonkov
    Aug 18, 2003
  2. Tony
    Replies:
    2
    Views:
    405
    =?Utf-8?B?cmVjb2lsQGNvbW11bml0eS5ub3NwYW0=?=
    May 24, 2006
  3. Replies:
    9
    Views:
    423
    Default User
    Apr 28, 2005
  4. Amit_Basnak
    Replies:
    3
    Views:
    311
    Alf P. Steinbach
    Nov 16, 2006
  5. Tony

    Expert advice needed on some strange event handling

    Tony, May 24, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    140
Loading...

Share This Page