mike_nudget ha scritto:
Pare che Request.QueryString("documento") non sia definita.
riposto il codice del codebihind :
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")
Dim DocID As String = Request.QueryString("Doc_ID")
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 DocID As Integer = Convert.ToInt32(Request.QueryString("Doc_ID"))
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionStrings:databaseConnectionString8").ConnectionString)
Const SQL As String = "SELECT [contenttype], [documento] FROM [upload] WHERE [documento] = @documento"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Doc_ID", DocID)
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 DocID As Integer = Convert.ToInt32(Request.QueryString("Doc_ID"))
Const SQL As String = "SELECT contenttype,documento FROM upload WHERE documento= @documento"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@Doc_ID", DocID)
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.ContentType = "application/pdf"
Response.BinaryWrite(thumbnailByteArray)
Response.Flush()
Response.End()
Loop
reader.Close()
myConnection.Close()
End Using
End Sub
End Class
mi da errore sulla
Line 58: Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionStrings:databaseConnectionString8").ConnectionString)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. l'errore può dipendere dal fatto che il codebihind del datalist è in c# e quello di view_document per vedere il documento è in vb.net?