user3804364
user3804364

Reputation: 23

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. But i am getting the error as access to the path is denied. Please help me out.

Upvotes: 0

Views: 588

Answers (1)

Manish Parakhiya
Manish Parakhiya

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

Related Questions