如何压缩文件夹 [英] How to zip a folder
本文介绍了如何压缩文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个链接.当用户单击此按钮时,我想运行一些代码来压缩我桌面上的文件夹,然后开始下载它.
I have a link. When user will click this button, I want to run some code that will zip a folder on my desktop and, start downloading it.
文件夹路径为C:/users/dave/desktop/myFolder
在 aspx 文件中:
<asp:HyperLink ID="HyperLink1" runat="server">zip folder and download </asp:HyperLink>
在 aspx.vb 文件中:
如何在此处编写代码以压缩桌面上的文件夹并开始下载此 zip 文件夹?有没有办法不用下载额外的库和插件呢?
How can I write code here that will zip a folder on my desktop and start downloading this zip folder? Is there way to do it without downloading extra libraries and plugins?
推荐答案
添加对 System.IO.Compression.FileSystem
然后您可以使用以下命令压缩文件夹:
Then you can zip the folder using the following:
Dim tempFile = System.IO.Path.GetTempFileName() + ".zip"
System.IO.Compression.ZipFile.CreateFromDirectory("C:\temp\awesome", tempFile)
然后下载它,你可以在响应中发送它:
Then to download it, you can send it in the response:
Response.Buffer = false
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=Desktop.zip")
Response.ContentType = "Application/zip"
Response.TransmitFile(tempFile)
Response.End()
这篇关于如何压缩文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文