我有一个文件夹中有3-4 pdf
文件。 SO按钮点击,我想下载PDF文件作为ZIP
文件。为此,我写下面的代码Zip文件没有越来越下载使用asp.net
string strFilePath = HttpContext.Current.Server.MapPath("~/UploadedFiles/" + SAP_ID + '_' + CANDIDATEID + "\\" + SAP_ID + '_' + CANDIDATEID + ".pdf");
string strDirectory = HttpContext.Current.Server.MapPath("~/UploadedFiles/" + SAP_ID + '_' + CANDIDATEID);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
if (Directory.Exists(strDirectory))
{
if (File.Exists(strFilePath + ".zip"))
{
var filestream = new System.IO.FileStream(strFilePath + ".zip", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
filestream.Close();
File.Delete(strFilePath + ".zip");
}
}
// ZipFile.CreateFromDirectory(strDirectory, strDirectory + ".zip");
var stream = new FileStream(strDirectory + ".zip", FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = Path.GetFileName(strDirectory + ".zip");
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentLength = stream.Length;
但按钮上点击ZIP没有得到下载和浏览器刚加载。
请帮我知道是什么原因?
可以检查zip文件是否在服务器上创建的? – minhhn2910
@ minhhn2910:好的,让我检查。 – BNN
@ minhhn2910:没有,现在,当我调试我的代码,我得到了错误的'{“找不到文件“d:\\ \\用户名\\ VSATFINAL_353 \\ VSATTSSRSurvey \\ UPLOADEDFILES I-BR-RNCH-ENB-0243_C3 .zip'.'在行'变种流=新的FileStream(strDirectory + “的.zip”,FileMode.Open);' – BNN