我想从我的本地 PC 下载一个 excel 文件格式,所以我写了我的代码如下
protected void btnDownloadExcelTemp_Click(object sender, EventArgs e)
{
try
{
string strFileFormat = System.Configuration.ConfigurationManager.AppSettings["FormateFilePath"].ToString();
string strFilePath = HttpContext.Current.Server.MapPath(strFileFormat + "/CMP_TEMPLATES.xlsx");
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AppendHeader("content-disposition", "attachment; filename=" + "CMP_TEMPLATES.xlsx");
response.ContentType = "application/octet-stream";
response.WriteFile(strFilePath);
response.Flush();
response.End();
}
catch (Exception)
{
throw;
}
}
并且strFileFormat
是<add key="FormateFilePath" value="D:/Name/CMP/CMP Excel Template"/>
因此,在下载时出现错误
'D:/Name/CMP/CMP Excel Template/CMP_TEMPLATES.xlsx' 是物理路径,但应为虚拟路径。
我不知道它期待什么路径。请建议