ASP.NET c# code: Zipping files and saving files to client local computer  with save file dialog box

Posted on 2013-11-30
Last Modified: 2013-12-02
The following code saves the zipped file in the server.
I have Ionic.Zip.dll in the bin folder
using System.IO;
using Ionic.Zip;
protected void btnzip_Click(object sender, EventArgs e)
string path = Server.MapPath("~/App_Info_Folders/" + lblattfld.Text + "/");
        string[] filenames = Directory.GetFiles(path);

        using (ZipFile zip = new ZipFile())
            zip.AddFiles(filenames, "files");

            lblmessage.Text = "ZIP File Created Successfully";

I want the code to be modified in such a way that the zipped file is directly saved on the client local computer through save file dialog box.
Question by:smanthanims

Expert Comment

by:Mohit Vijay
ID: 39687872
What is meaning of Directly save? If you want to save on client computer without informing user, it will not be possible, because of security issues in web application. Can be done with Windows Application only.

Expert Comment

ID: 39687878
Please check this link;

Client download samples

Author Comment

ID: 39688083
To VJsoft:
I mean save directly (without saving on server) on client computer of course with knowledge of user. Save file dialog box permits user to save on any location on the client user computer. I do not think the code is difficult at all. I am not able recall now.
XGIS: client download samples are not helpful. I had seen them before approaching Experts-Exhange.
LVL 27

Accepted Solution

Chinmay Patel earned 300 total points
ID: 39689216


Open in new window

put this code

string strURL=Server.MapPath("~/");
          WebClient req=new WebClient();
          HttpResponse response = HttpContext.Current.Response;
          response.Buffer= true;
          response.AddHeader("Content-Disposition","attachment;filename=\"" + Server.MapPath(strURL) + "\"");
          byte[] data=req.DownloadData(Server.MapPath(strURL));

Open in new window


Author Closing Comment

ID: 39689714
Apt and complete solution. The code is working to my expectations. Only a small correction is required
Intead of
string strURL=Server.MapPath("~/");
we need to use
string strURL = "~/";

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error on Add method 1 38
Help with C#, MVC, razor. 6 23
Exit the loop 4 35 show message while code is running 3 9
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now