Solved

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

Posted on 2013-11-30
5
2,453 Views
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");
            zip.Save(Server.MapPath("~/samplefiles.zip"));

            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.
0
Comment
Question by:smanthanims
5 Comments
 
LVL 8

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.
0
 
LVL 7

Expert Comment

by:XGIS
ID: 39687878
Please check this link;

Client download samples
0
 

Author Comment

by:smanthanims
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.
To:
XGIS: client download samples are not helpful. I had seen them before approaching Experts-Exhange.
0
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 300 total points
ID: 39689216
after

  zip.Save(Server.MapPath("~/samplefiles.zip"));

Open in new window


put this code

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

Open in new window


Source: http://venkateswarlu.co.in/DotNet/download_file.aspx
0
 

Author Closing Comment

by:smanthanims
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("~/samplefiles.zip");
we need to use
string strURL = "~/samplefiles.zip";
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Setting up a IIS 8 Web Server to send and receive XML files 7 89
How to filter by key press ? 6 54
Header Font Size in Grid View 6 22
Need help with a query 14 33
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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