Sending a Zip File to a Client via Reply Using DotNetZip

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 moment i'm just trying to get the 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 readme.txt document (expected) without text inside the document (unexpectedly).

This code is almost verbatim from the example here . What makes me so that other people are faced with this exact problem.

My ultimate 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 lines as files to the zip file, but I agree that an example will now show.

Anyone have any suggestions?

thanks

- UPDATE-- , , , , , DLL , - . .

+3
3

:

HttpContext.Current.ApplicationInstance.CompleteRequest();    

Response.Close();

, HTML-, zip .

+1

AddFile = , .

0

, CodePlex, , AddEntry . - , StringReader, ReadmeText ?

0
source

Source: https://habr.com/ru/post/1713043/


All Articles