I have a download page where there are 3 download options: Word, Zip, and PDF. There is a folder containing .doc
files. When a user clicks the Zip option on the page, I want ASP.NET to zip the folder with the .doc
files into a temporary .zip
file. Then the client will download it from the server. When the user's download is finished, the temporary Zip file should delete itself.
How can I do this with ASP.NET 2.0 C#?
Note: I know how I can zip and unzip files and remove files from the system with C# ASP.NET 2.0.
To delete the compressed version, right-click the zipped folder > Choose [Delete].
Zip files are usually downloaded to a location that is specific to your operating system. For Windows-based computers, zip files are typically saved in the My Documents or Downloads folder unless you've specified something else as the default download destination for your computer.
After the download is complete, navigate to the ZIP file on your computer. You should be able to right-click or (if you are using Mac OS X) control-click on the file. At least one of the following options should appear in the menu: Extract, Extract All, Unzip.
Using DotNetZip you can save the zip file directly to the Response.OutputStream. No need for a temporary Zip file.
Response.Clear();
// no buffering - allows large zip files to download as they are zipped
Response.BufferOutput = false;
String ReadmeText= "Dynamic content for a readme file...\n" +
DateTime.Now.ToString("G");
string archiveName= String.Format("archive-{0}.zip",
DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + archiveName);
using (ZipFile zip = new ZipFile())
{
// add a file entry into the zip, using content from a string
zip.AddFileFromString("Readme.txt", "", ReadmeText);
// add the set of files to the zip
zip.AddFiles(filesToInclude, "files");
// compress and write the output to OutputStream
zip.Save(Response.OutputStream);
}
Response.Flush();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With