[問題] 一次下載多筆資料庫的image資料
各位好 我用的資料庫是Microsoft SQL Server
我用類似下面的語法可以把某筆image資料 下載成一個檔案
http://goo.gl/2bWGL4
但這樣每次只能下載一個檔案
請問 有辦法一次下載多筆嗎? 或者是一次下載多筆檔案所壓縮而成的zip檔
謝謝
---------------------------------------------------
byte[] xfile = null;
string docupath = Request.PhysicalApplicationPath;
xfile = wc.DownloadData(docupath + "uploads\\qrcode.png");
string xfileName = System.IO.Path.GetFileName
(docupath + "uploads\\qrcode.png");
HttpContext.Current.Response.AddHeader("content-disposition",
"attachment;filename=" + HttpContext.Current.Server.UrlEncode(xfileName));
HttpContext.Current.Response.ContentType = "application/octet-stream";
//二進位方式
HttpContext.Current.Response.BinaryWrite(xfile); //內容轉出作檔案下載
HttpContext.Current.Response.End();
----------------------------------------------------------------
我後來使用DotNetZip來壓縮檔案 https://dotnetzip.codeplex.com/
右邊是官方提供的一些 C# Examples https://goo.gl/FNjqug
作法大致如下 先宣告一個MemoryStream
MemoryStream ms = new MemoryStream();
再宣告一個ZipFile 透過AddEntry 把從資料庫撈出的檔案加進去ZipFile
接著用Save把壓縮檔存到一開始宣告的MemoryStream中
ZipFile zip = new ZipFile());
zip.AddEntry("檔名",stream或byte[]); // stream或byte[]就是從資料庫撈出的檔案
zip.Save(ms);
最後透過Response.BinaryWrite 把一開始宣告的MemoryStream下載下來
Response.BinaryWrite(ms.ToArray());
以上供有相同問題的人參考
謝謝大家幫忙
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.127.81.14
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1463728684.A.825.html
→
05/21 03:22, , 1F
05/21 03:22, 1F
→
05/21 03:23, , 2F
05/21 03:23, 2F
→
05/21 03:24, , 3F
05/21 03:24, 3F
→
05/21 03:25, , 4F
05/21 03:25, 4F
→
05/21 17:23, , 5F
05/21 17:23, 5F
→
05/21 17:25, , 6F
05/21 17:25, 6F
→
05/21 19:08, , 7F
05/21 19:08, 7F
→
05/21 19:08, , 8F
05/21 19:08, 8F
→
05/21 19:11, , 9F
05/21 19:11, 9F
→
05/21 19:11, , 10F
05/21 19:11, 10F
→
05/21 19:12, , 11F
05/21 19:12, 11F
→
05/21 19:16, , 12F
05/21 19:16, 12F
※ 編輯: kisha024 (140.127.81.14), 06/09/2016 18:08:00
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章