I created one pdf document
var document = new Document();
string path = Server.MapPath("AttachementToMail");
PdfWriter.GetInstance(document, new FileStream(path +
"/"+DateTime.Now.ToShortDateString()+".pdf", FileMode.Create));
Now I want to download this document
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename="+
DateTime.Now.ToShortDateString() + ".pdf" + "");
Response.TransmitFile(path);
Response.End();
but it gave me error
Access to the path ‘~\AttachementToMail’ is denied.
read / write access for IIS_IUSRS exists
The path you are providing to write is a virtual path.
TransmitFileexpects an absolute path.Your code should look something like this:
DateTime.Nowrepresents the current time. Be careful when you use it as the file name.Using
ToShortDateStringis a little risky, as some cultures put/in that format. UsingToStringwill allow you to fix your filename format regardless of the server culture.