0

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.

Folder path is C:/users/dave/desktop/myFolder

in aspx file:

<asp:HyperLink ID="HyperLink1" runat="server">zip folder and download </asp:HyperLink>

In aspx.vb file:

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?

T.S.
  • 15,962
  • 10
  • 52
  • 71
user1924249
  • 503
  • 2
  • 12
  • 34

1 Answers1

0

Add a reference to 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()
John Koerner
  • 36,569
  • 8
  • 80
  • 129