while im exporting, one pdf is downloading in desired location but another extra pdf is downloading in downloads folder
How to stop downloading extra one pdf?
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + Projname + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
design.RenderControl(htmlWrite);
string myText = stringWrite.ToString().Replace("&", "&");
StringReader sr = new StringReader(myText.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
string strPath = "D:\\WeeklyReport of " + Projname + ".pdf";
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(strPath, FileMode.Create));
pdfDoc.Open();
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
pdfDoc.Close();
pdfDoc.Dispose();
This line
of your code calls for a
PdfWriter
writing to a file on the server file system.If you don't want that, you have to replace the
new FileStream(strPath, FileMode.Create)
by something else, e.g. the HTTP response output stream:This has potential disadvantages,
If these drawbacks worry you, you may probably instead want to instantiate a
MemoryStream
, target thePdfWriter
to it, build the PDF, retrieve thebyte[]
from the stream, create a content length header for the size of that array, and finally write the array toResponse.OutputStream
.