I have a aspx page that creates a PDF file to Download to the client´s browser and it works fine. But I need to create that file into the server too and that´s the problem.
How i can to transform Response.OutputStream to a File into the server?
here is my code:
protected void Page_Load(object sender, EventArgs e)
{
try
{
JavaScriptSerializer jss = new JavaScriptSerializer();
DestinationPDF.DestinationPDF.DestinationPDFParameters dPdfParams = jss.Deserialize<DestinationPDF.DestinationPDF.DestinationPDFParameters>(Request["destinationPdfValue"]);
dPdfParams.DocAttributes.MarginBottom = 10;
dPdfParams.DocAttributes.MarginLeft = 10;
dPdfParams.DocAttributes.MarginRight = 10;
dPdfParams.DocAttributes.MarginTop = 10;
dPdfParams.DocAttributes.FileName = "Acreditacion_" + Request["id"];
DestinationPDF.DestinationPDF dPdf = new DestinationPDF.DestinationPDF(dPdfParams.Widgets,dPdfParams.DocAttributes);
Response.AppendHeader("Content-disposition", string.Format("attachment;filename={0}", dPdf.GetFileName()));
Response.ContentType = "application/pdf";
dPdf.Save(Response.OutputStream);
Stream stream = Response.OutputStream;
var fileStream = new FileStream(@"C:\PROYECTOS 2013\CANCILLERIA\PortalTramites\PortalTramites\Documentos\pdf__Acreditacion" + Request["id"] + ".pdf", FileMode.Create, FileAccess.Write);
stream.CopyTo(fileStream, 256);
}
catch (Exception ex) { Response.End(); }
Response.End();
}