que puedo porque navegador mis los internet hacer evitar descargar cómo con chrome archivos archivo abrir abren abran abra c# .net pdf streaming memorystream

c# - porque - no puedo abrir archivos pdf en mi pc



¿Cómo establecer el nombre del archivo al transmitir un PDF en un navegador? (2)

No estoy seguro exactamente cómo redactar esta pregunta ... ¡así que las ediciones son bienvenidas! De todos modos ... aquí va.

Actualmente uso Crystal Reports para generar Pdfs y simplemente transmitir el resultado al usuario. Mi código se parece a lo siguiente:

System.IO.MemoryStream stream = new System.IO.MemoryStream(); stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); this.Response.Clear(); this.Response.Buffer = true; this.Response.ContentType = "application/pdf"; this.Response.BinaryWrite(stream.ToArray()); this.Response.End();

Después de ejecutar este código, transmite el Pdf al navegador que abre Acrobat Reader. ¡Funciona genial!

Mi problema es cuando el usuario intenta guardar el archivo predeterminado para el nombre del archivo real ... en este caso, por defecto, es CrystalReportPage.pdf. ¿Hay alguna manera de configurar esto? ¿Si es así, cómo?

Cualquier ayuda sería apreciada.


Por lo general, a través del encabezado de disposición de contenido, es decir,

Content-Disposition: inline; filename=foo.pdf

Así que solo use Headers.Add, o AddHeader, o lo que sea, con:

response.Headers.Add ("Content-Disposition", "inline; filename = foo.pdf");

(en línea es "mostrar en el navegador", el archivo adjunto es "guardar como un archivo")


System.IO.MemoryStream stream = new System.IO.MemoryStream(); stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); this.Response.Clear(); this.Response.Buffer = true; this.Response.ContentType = "application/pdf"; this.Response.AddHeader("Content-Disposition", "attachment; filename=/""+FILENAME+"/""); this.Response.BinaryWrite(stream.ToArray()); this.Response.End();