Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stream was not readable from mscorelib with BinaryReader with PDF

Status
Not open for further replies.

johneydluca

Programmer
May 29, 2002
25
US
Hello

I am getting error when I try to open PDF documdent using binary read.
Line # 106 where error is occuring is binaryReader = New BinaryReader(HttpWResp.GetResponseStream())


Error Source mscorlib : Stream was not readable.
System.ArgumentException: Stream was not readable. at System.IO.BinaryReader..ctor(Stream input, Encoding encoding) at System.IO.BinaryReader..ctor(Stream input) at FileNetSearch.FileNetSearch.GetReport.ReturnPictureBinary(String sUrl, String& sContentType, String& sErrTxt) in c:\inetpub\ 106


Does anyone has any idea what is going worng in this.

Thanks a lot in advance

JD

following is my source code.
Public Class GetPDF
Inherits System.Web.UI.Page


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


sServer = System.Configuration.ConfigurationSettings.AppSettings.Get("ServerPathMetaData")
sImageUrl = "ContainerId=" & ContId & "&ContentId=" & StmtContentId & "&RepositoryId=" & RepId & ""
sfileName = " & sServer & "/GetDocs.aspx?" & sImageUrl & "&searchType=get_content "
sContentType = "application/pdf"

Dim documentByteArray() As Byte = Nothing
documentByteArray = ReturnPictureBinary(sfileName, sContentType, sErrTxt)
If documentByteArray Is Nothing Then
Response.Write(sErrTxt)
Else
Response.ContentType = sContentType
Response.BinaryWrite(documentByteArray)
Response.Flush()
Response.End()
End If




End Sub

Public Function ReturnPictureBinary(ByVal sUrl As String, ByRef sContentType As String, ByRef sErrTxt As String) As Byte()


Dim Uri As Uri = New Uri(sUrl)
sErrTxt = ""
Dim HttpWReq As HttpWebRequest
HttpWReq = WebRequest.Create(sUrl)
HttpWReq.KeepAlive = False

Dim HttpWResp As HttpWebResponse
HttpWResp = HttpWReq.GetResponse()
Dim binaryReader As BinaryReader
Dim documentByteArray() As Byte = Nothing
Dim contentLength As Int32 = Convert.ToInt32(HttpWResp.ContentLength)
Try

If (contentLength < 0) Then
documentByteArray = Nothing
sErrTxt = "Unable To Retrieve The Document."
HttpWResp.Close()
ReturnPictureBinary = documentByteArray
End If

If (HttpWResp.ContentType = "application/x-msexcel") Then
sContentType = "application/x-msexcel"
ElseIf (HttpWResp.ContentType = "application/pdf") Then
sContentType = "application/pdf"
End If


binaryReader = New BinaryReader(HttpWResp.GetResponseStream())
documentByteArray = binaryReader.ReadBytes(contentLength)
HttpWResp.Close()
ReturnPictureBinary = documentByteArray

Catch ex As Exception
sErrTxt = "<B>Error Source " & ex.Source & " : " & ex.Message & "</b> <BR>" & ex.ToString
ReturnPictureBinary = Nothing
End Try

End Function
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top