views:

673

answers:

3

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.

A: 

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

ck
I just tried this, it seems as though doing something like zip.addFile("somefile.txt") gives me a file not found exception
jim
addFile looks like the way to add a file on disk.
jim
A: 

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?

Graham Clark
it seems as though it's overloaded to take a string
jim
oh right, I haven't looked at the actual API, just at the example on the web page.
Graham Clark
I haven't seen the API at all, I've gone from the examples and they are poor, or at the very least I'm too stupid to figure them out. I don't know where to go from here other than find an alternative solution, like use something else.
jim
+1  A: 

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.

Cheeso
thank you cheeso.
jim