Salve
ho un problema nel vedere il documento (memorizzato in un database sql server come binary data)...allora ho il seguente hiperlink datalist :
<ItemTemplate>
<asp:HyperLink ID="view_document" runat="server" Target=_blank
NavigateUrl='<%# "~/view_image.aspx?Doc_ID=" + Eval("Doc_ID").ToString() %>'
Text='<%# Eval("titolo") %>' /> <br />
inoltre ho creato una pagina vuota view_image.aspx per vedere il documento allegato
questo il code behind di view_image.aspx (preso da un post qui sul forum) :
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data.OleDB
Partial Class View_Document
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim contenttype As String = Request.QueryString("contenttype")
If contenttype = "application/msword" Or contenttype = "application/zip" Or contenttype = "application/vnd.ms-excel" Or contenttype = "image/gif" Or contenttype = "image/jpeg" Then
NOT_PDF()
Else
contenttype = "application/pdf"
PDF()
End If
End Sub
Sub NOT_PDF()
Dim ImageID As Integer = Convert.ToInt32(Request.QueryString("Doc_ID"))
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("DebtorsConnectionString").ConnectionString)
Const SQL As String = "SELECT [contenttype], [documento] FROM [upload] WHERE [Doc_ID] = @Doc_ID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Doc_ID"", ImageID)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader
If myReader.Read Then
Response.ContentType = myReader("contenttype").ToString()
Response.BinaryWrite(myReader("documento"))
End If
myReader.Close()
myConnection.Close()
End Using
End Sub
Sub PDF()
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionStrings:databaseConnectionString8").ConnectionString)
Dim ImageID As Integer = Convert.ToInt32(Request.QueryString("Doc_ID""))
Const SQL As String = "SELECT contenttype,documento FROM upload WHERE Doc_ID= @Doc_ID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Cognome", ImageID)
Dim reader As SqlDataReader
myConnection.Open()
reader = myCommand.ExecuteReader()
Do While reader.Read()
Dim byteArray As Byte() = CType(reader("documento"), Byte())
Dim mstream As New System.IO.MemoryStream(byteArray, 0, byteArray.Length)
Dim thumbnailByteArray(mstream.Length) As [Byte]
mstream.Position = 0
mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length))
Response.ClearHeaders()
Response.ClearContent()
Response.BinaryWrite(thumbnailByteArray)
Response.Flush()
Response.End()
Loop
reader.Close()
myConnection.Close()
End Using
End Sub
End Class
quando si apre la pagina dell hyper link è vuota e nn mi apre il pdf come mai?
nel database il documento binary data è memorizzato nel campo documento .. nn riesco a capire dove sbaglio help me please!
Modificato da webmauro il 10 agosto 2007 18.41 -