Ciao, puoi vedere se questo codice ti funziona?
codice:
'---------------------------------------------------------------------------------------------------------------------------------------------------
'salva buffer di byte nello stream di uscita come attachemt
'---------------------------------------------------------------------------------------------------------------------------------------------------
Public Sub SaveDocOutputStreamAttachment(buffer As Byte(), nomeDocumento As String, Optional contentType As String = "application/octet-stream")
System.Web.HttpContext.Current.Response.Clear()
System.Web.HttpContext.Current.Response.HeaderEncoding = Encoding.Default
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=""{0}""", nomeDocumento))
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", buffer.Length.ToString)
System.Web.HttpContext.Current.Response.ContentType = contentType
If buffer.Length > 0 Then
'queste due istruzioni sono equivalenti
System.Web.HttpContext.Current.Response.OutputStream.Write(buffer, 0, buffer.Length)
'System.Web.HttpContext.Current.Response.BinaryWrite(buffer)
End If
System.Web.HttpContext.Current.Response.Flush() : System.Web.HttpContext.Current.Response.End()
End Sub
codice:
'=================================================================================
'application/octet-stream
'application/pdf
'application/json
'application/xml
'application/zip
'text/csv
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet