Ive得到了一個文件下載的問題你能幫助我爲......多個圖像文件夾從保存到本地在asp.net
這裏是代碼:
DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(@"/Bailiffs/BailiffFiles/"));
string cukurNumber = string.Empty;
if (txtCukurNumber.Text != string.Empty) {
cukurNumber = txtCukurNumber.Text;
}
FileInfo[] fileInfoEnum = directoryInfo.GetFiles(cukurNumber + "*");
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + txtCukurNumber.Text + ".zip");
Response.ContentType = "application/zip";
using (ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream)) {
zipStream.SetLevel(9);
byte[] zipBuffer = new byte[4096];
foreach (FileInfo fileInfo in fileInfoEnum) {
string fileFullName = fileInfo.FullName;
ZipEntry zipEntry = new ZipEntry(Path.GetFileName(fileFullName));
zipEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(zipEntry);
using (FileStream fileStream = File.OpenRead(fileFullName)) {
int sourceBytes = 0;
do {
sourceBytes = fileStream.Read(zipBuffer, 0, zipBuffer.Length);
zipStream.Write(zipBuffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
zipStream.Finish();
zipStream.Close();
Response.Flush();
Response.End();
}
這個代碼必須獲得通過過濾器的所有圖像文件並保存到磁盤上,而瀏覽器保存文件對話框打開只是一個時間和一個奇怪的文件保存...其中,我做錯了什麼......
感謝..
編輯: Bizzarre文件問題現在解決的主要問題是單個文件保存,而不是多個.. 再次感謝...
你能澄清:你想要的圖片到本地客戶端保存爲一個單一的形象?或者您是否希望它爲每個下載的圖像多次提示用戶? – Aaron