locked
Troubles with SharpLibZip RRS feed

  • General discussion

  • Hi everyone!

     

    I'm finding a lot of troubles and problems with SharLibZip library...i really don't know how to resolve this problem:

     

    I've got an ArrayList of element, resulting from a Select operation from a DB.

     

    I've got an aspx page where user can export those infos in .xls or .txt formats.

    He can export in his own pc those infos in normal excel format/normal text format or in compressed format (excel/text compressed in zip file).

     

    Here's my script, focus on EXCEL choice:

    Code Snippet

    //elenco is the ArrayList with DB's elements

     

     

    if (rbFormato.SelectedValue == "EXCEL")
                {
                    Response.Clear();
                    Response.Buffer = true;
                   

                    if (rbModPag.SelectedValue == "ESTESO")
                    {

     

    Response.ContentType = "application/vns.ms-excel;filename=\"ElencoPagamenti.xls\"";
                        Response.Charset = "";
                        this.EnableViewState = false;

                        System.IO.StringWriter tw = new System.IO.StringWriter();

                        //Prima riga di intestazione
                        tw.Write("Pagamento\t");
                        tw.Write("Mod. Pag.\t");
                        tw.Write("Anno Imp.\t");


     

                        foreach (DatiPagamento datiPag in elenco)
                        {
                            tw.Write(datiPag.TipoPag + "\t");
                            tw.Write(datiPag.ModPag + "\t");
                            tw.Write(datiPag.AnnoImposta + "\t");
                            tw.Write("\t\r");
                        }

     

                        Response.Write(tw.ToString());

    Response.End();
    }
    else
    {

    Response.ContentType = "application/x-zip;filename=\"ElencoPagamenti.zip\"";
                        Response.Charset = "";
                        this.EnableViewState = false;

                        System.IO.StringWriter tw = new System.IO.StringWriter();

                        //Prima riga di intestazione
                        tw.Write("Pagamento\t");
                        tw.Write("Mod. Pag.\t");
                        tw.Write("Anno Imp.\t");


     

                        foreach (DatiPagamento datiPag in elenco)
                        {
                            tw.Write(datiPag.TipoPag + "\t");
                            tw.Write(datiPag.ModPag + "\t");
                            tw.Write(datiPag.AnnoImposta + "\t");
                            tw.Write("\t\r");
                        }

     

                        ZipOutputStream s = new ZipOutputStream(Response.OutputStream);
                        byte[] buffer = Encoding.ASCII.GetBytes(tw.ToString());
                        ZipEntry myEntry = new ZipEntry("ElencoPagamenti.xls");

                        s.PutNextEntry(myEntry);   /*EXCEPTION*/
                        s.Write(buffer, 0, buffer.Length);

                        s.Close();
                        tw.Close();

                    }
                }

     

     

    The exception thrown is:

    'Specified argument was out of the range of valid values.

    Parameter name: offset'

     

    I don't want to specify the location where the zip file will be saved: user will be specify it (when the window appear)...

     

    How I can resolve it?

     

    Thanks a lot...i'm going crazy! :-s

    Wednesday, April 30, 2008 3:06 PM

All replies