将页面下载为 pdf 文件并保存在 C# 中的本地文件夹中
本文关键字:存在 文件夹 保存 下载 文件 pdf | 更新日期: 2023-09-27 18:24:04
protected void btn_download_Click(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf");
string filePath = Server.MapPath(Request.ApplicationPath) + " ''Member''Attachments" ;
Response.TransmitFile(filePath);
Response.End();
}
我使用上面的链接代码将网页下载到 pdf 文件并保存在本地文件中。但是我收到错误,因为对路径的访问被拒绝。请帮帮我。
filePath 变量中缺少本地文件名。将文件名附加到它。并确保您的附件目录有权访问IIS用户的文件。
string filePath = Server.MapPath(Request.ApplicationPath) + " ''Member''Attachments''foo.pdf" ; ''Append your file name here.