简体   繁体   English

将页面下载为pdf文件并保存在C#的本地文件夹中

[英]to download a page as pdf file and save in a local folder in C#

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(); 
}

I used the above link code to download a webpage to a pdf file and save in a local file. 我使用上面的链接代码将网页下载为pdf文件并保存在本地文件中。 But i am getting the error as access to the path is denied. 但由于路径访问被拒绝,我遇到了错误。 Please help me out. 请帮帮我。

Missing local file name in filePath variable. filePath变量中缺少本地文件名。 Append file name to it. 附加文件名。 And make sure that you attachment directory have permission to access files for IIS users. 并确保您的附件目录具有访问IIS用户文件的权限。

string filePath = Server.MapPath(Request.ApplicationPath) + " \\Member\\Attachments\\foo.pdf" ; \\Append your file name here.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM