Need to have "ICSharpCode.SharpZipLib.dll" to make it
Here MatchCollection is document paths.
Here MatchCollection is document paths.
private void DownloadZipToBrowser(MatchCollection matches,SPWeb web) { Response.ContentType = "application/zip"; // If the browser is receiving a mangled zipfile, IIS Compression may cause this problem. Some members have found that // Response.ContentType = "application/octet-stream" has solved this. May be specific to Internet Explorer. Response.AppendHeader("content-disposition", "attachment; filename=\"Memo.zip\""); Response.CacheControl = "Private"; Response.Cache.SetExpires(DateTime.Now.AddMinutes(3)); // or put a timestamp in the filename in the content-disposition byte[] buffer = new byte[4096]; ZipOutputStream zipOutputStream = new ZipOutputStream(Response.OutputStream); zipOutputStream.SetLevel(3); //0-9, 9 being the highest level of compression foreach (Match m in matches) { SPFile oFile = web.GetFile(m.Result("${url}")); Stream fs = oFile.OpenBinaryStream(); //Stream fs = File.OpenRead(fileName); // or any suitable inputstream ZipEntry entry = new ZipEntry(ZipEntry.CleanName(oFile.Name)); entry.Size = fs.Length; // Setting the Size provides WinXP built-in extractor compatibility, // but if not available, you can set zipOutputStream.UseZip64 = UseZip64.Off instead. zipOutputStream.PutNextEntry(entry); buffer = new byte[fs.Length]; int count = fs.Read(buffer, 0, buffer.Length); while (count > 0) { zipOutputStream.Write(buffer, 0, count); count = fs.Read(buffer, 0, buffer.Length); if (!Response.IsClientConnected) { break; } Response.Flush(); } fs.Close(); } zipOutputStream.Close(); Response.Flush(); Response.End(); }
No comments:
Post a Comment