谁能请解释一下这个代码下载代码expalanation
if (e.CommandName == "download")
{
string filename = e.CommandArgument.ToString();
string path = MapPath("~/Docfiles/" + filename);
byte[] bts = System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "Application/octet-stream");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
Response.End();
}
是什么命令参数,MapPath的,也这是什么 “内容类型”,“应用程序/八位字节流” 也
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.BinaryWrite(bts);
Response.Flush();
您可以尝试谷歌条款。 – Ofiris
我是如何找到这段代码的范围的..我没有发现这就是为什么我在这里发布 – user3338484
这是不言自明的。它是在用户单击按钮时下载文件。该文件位于应用程序根目录(〜/是应用程序根目录的简写)/ DocFiles目录中。当一个文件即时生成时,您通常会看到这种代码。 – Tim