59 messaggi dal 17 gennaio 2008
Ciao a tutti,

ho salvato un PDF all'interno del mio DB sqlserver come byte in un campo varbinary(max). Adesso vorrei poterlo visualizzare e/o scaricare, come faccio?
questo è il codice che utilizzo attualmente, ma sembra che non interpreti i byte ricevuti


Dim data As Byte() = dsFileCondizioni.Tables("Table").Rows(0)(0)
Response.AddHeader("Content-Length", data.Length.ToString())
Response.AddHeader("Accept-Ranges", "bytes")
Response.ContentType = "application/pdf"
               
Response.OutputStream.Write(data, 0, data.Length)
Response.Flush()
Response.Close()



c'è un'altra strada per far visualizzare il pdf?

Grazie
59 messaggi dal 17 gennaio 2008
RISOLTO!!! :D


 Dim doc As Byte() = dsFileCondizioni.Tables("Table").Rows(0)(0)

 Using ms As New System.IO.MemoryStream(doc)


 Dim dataLengthToRead As Long = ms.Length
 Dim blockSize As Integer = If(dataLengthToRead >= 5000, 5000, CInt(dataLengthToRead))
 Dim buffer As Byte() = New Byte(dataLengthToRead - 1) {}

 Response.Clear()

 ' Clear the content of the response
 Response.ClearContent()
 Response.ClearHeaders()

 ' Buffer response so that page is sent
 ' after processing is complete.
 Response.BufferOutput = True

 ' Add the file name and attachment,
 ' which will force the open/cance/save dialog to show, to the header
 Response.AddHeader("Content-Disposition", "attachment; filename=Condition.pdf")

 ' bypass the Open/Save/Cancel dialog
 'Response.AddHeader("Content-Disposition", "inline; filename=" + doc.FileName);

 ' Add the file size into the response header
 Response.AddHeader("Content-Length", doc.Length.ToString())

 ' Set the ContentType
 Response.ContentType = "application/octet-stream"

 ' Write the document into the response
 While dataLengthToRead > 0 AndAlso Response.IsClientConnected
   Dim lengthRead As Int32 = ms.Read(buffer, 0, blockSize)
   Response.OutputStream.Write(buffer, 0, lengthRead)
   Response.Flush()
   dataLengthToRead = dataLengthToRead - lengthRead
 End While

 Response.Flush()
 Response.Close()
 End Using

 ' End the response
 Response.[End]()

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.
Community
Ultimi messaggi
UTENTI ONLINE
    In primo piano

    I più letti di oggi

    Media
    In evidenza
    MISC