Question

this is my code

    private void sendToClient(Dictionary<string, string> reportDic)
    {
        Response.Clear();
        Response.BufferOutput = false;
        String ReadmeText = "some text";
        Response.ContentType = "application/zip";
        Response.AddHeader("content-disposition", "filename=" + "filename.zip");
        using (ZipFile zip = new ZipFile())
        {
            zip.AddEntry("Readme.txt", ReadmeText);
            zip.Save(Response.OutputStream);
        }
        Response.Close();
    }

at this point I'm simply trying to return a zip file with the readme.txt document inside the zip with the words "some text" inside the document.

What I get is a zipfile named filename.zip(expected) with a document readme.txt(expected) with no text inside of the doucment(unexpected).

This code is almost verbatim from the example here. Which makes me thing other people have run into this exact problem.

My end goal is to do something like this.

    private void sendToClient(Dictionary<string, string> reportDic)
    {
        Response.BufferOutput = false;
        Response.ContentType = "application/zip";
        Response.AddHeader("content-dispostion", "filename=text.zip");
        Response.ContentEncoding = Encoding.Default;
        Response.Charset = "";
        using (ZipFile zip = new ZipFile())
        {
            foreach (string key in reportDic.Keys)
            {
                zip.AddEntry(key, reportDic[key]);
            }
            zip.Save(Response.OutputStream);
        }
        Response.Close();
    }

add three strings as files to the zip file, but I'll settle for getting the example working for now.

Anyone have any suggestions?

Thanks

--UPDATE-- This should work, in fact if I copy it into a new project, it works just as advertised, I must have a toxic mix of dlls or some corruption in my project, that is obscure or something. Wonderful.

Was it helpful?

Solution

hint:

don't use

HttpContext.Current.ApplicationInstance.CompleteRequest();    

instead, use

Response.Close();

If you use the former, you will get HTML junk appended to the bottom of your zip file.

OTHER TIPS

Have you tried putting in the AddFile method with some dummy text = I think this is required.

The example you linked to on CodePlex seems to say the AddEntry method reads data from a stream. You're just passing in a string - maybe you could try creating a StringReader to look at your ReadmeText string, and pass this in instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top