Reputation: 23
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. But i am getting the error as access to the path is denied. Please help me out.
Upvotes: 0
Views: 588
Reputation: 3798
Missing local file name in filePath variable. Append file name to it. And make sure that you attachment directory have permission to access files for IIS users.
string filePath = Server.MapPath(Request.ApplicationPath) + " \\Member\\Attachments\\foo.pdf" ; \\Append your file name here.
Upvotes: 1