0
我正在使用webmethod下載.zip文件,但文件未下載。我的代碼沒有錯誤運行良好,代碼如下:
未在webmethod中下載的文件
[WebMethod]
public static void DownloadExtension(string ExtensionPath)
{
string filepath = HttpContext.Current.Server.MapPath(ExtensionPath);
FileInfo file = new FileInfo(filepath);
if (file.Exists)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = ReturnExtension(file.Extension.ToLower());
HttpContext.Current.Response.TransmitFile(file.FullName);
HttpContext.Current.Response.End();
}
}
private static string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".zip":
return "application/zip";
default:
return "application/octet-stream";
}
}
我使用VS2008 任何解決方案謝謝。