hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : ASP.net binary stream question
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

ASP.net binary stream question

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 05-11-2004, 10:31 AM
stormraven stormraven is offline
WHT Addict
 
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
Question

ASP.net binary stream question


I have a question I'm hoping someone can help me with. I'm using ASP.net, and I'm trying to return a .PDF file that I get from another server (one located inside the firewall generated by another application).

Here's the code I have so far.. I get something back, but it's very garbled..

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim target As String
        Dim sStream As System.IO.Stream
        Dim buffer(256) As Byte
        Dim count As Integer

        count = 0

        target = "http://someotherserver/someaddress"
        sStream = Get_HTMLContent(target)
        Response.ClearHeaders()

        Response.AddHeader("Content-Disposition", "filename=statement.pdf")
        Response.AddHeader("Content-Type", "application/pdf")
        Response.AddHeader("Charset", "UTF-8")

        count = sStream.Read(buffer, 0, 256)
        Response.BinaryWrite(buffer)

        While (count > 0)
            count = sStream.Read(buffer, 0, 256)
            Response.BinaryWrite(buffer)
        End While

        Response.Flush()

        sStream.Close()

    End Sub
Anybody, anybody?

__________________
Paul Embry
Knight Software and Web Design
Paul.Embry@gmail.com
Quality PHP Web Programming for Reasonable Prices

Reply With Quote


Sponsored Links
  #2  
Old 05-11-2004, 10:01 PM
ACW ACW is offline
Aspiring Evangelist
 
Join Date: Jan 2004
Posts: 406
Is the result opening as a PDF or are you just getting text?

Reply With Quote
  #3  
Old 05-11-2004, 10:59 PM
stormraven stormraven is offline
WHT Addict
 
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
The result comes through as text (i.e, Adobe doesn't fire up like it should) but it surely isn't human readable.

I came up with some other code that (almost) worked - it fired up Adobe but then said the result was garbled. I'll post it when I get back to work tomorrow.

__________________
Paul Embry
Knight Software and Web Design
Paul.Embry@gmail.com
Quality PHP Web Programming for Reasonable Prices

Reply With Quote
Sponsored Links
  #4  
Old 05-12-2004, 11:56 AM
stormraven stormraven is offline
WHT Addict
 
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
Here's the code that at least makes Adobe fire up - in other words, it thinks there's a PDF file there but it's garbled so it won't actually show up. Anyone have any thoughts?

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim target As String
        Dim resp As String
        Dim sStream As System.IO.Stream
        Dim buffer(256) As Byte
        Dim count As Integer

        count = 0

        target = "http://myurl"
        resp = Get_HTMLContent(target)
        Response.ClearHeaders()

        Response.AddHeader("Content-Disposition", "filename=statement.pdf")
        Response.AddHeader("Content-Type", "application/pdf")
        Response.AddHeader("Charset", "UTF-8")

        Response.Write(resp)
        Response.Flush()

    End Sub

    Function Get_HTMLContent(ByVal sURL As String) As String
        Dim sStream As Stream
        Dim URLReq As HttpWebRequest
        Dim URLRes As HttpWebResponse
        Dim reader As StreamReader


        URLReq = WebRequest.Create(sURL)
        URLRes = URLReq.GetResponse()

        sStream = URLRes.GetResponseStream()
        reader = New StreamReader(sStream, System.Text.Encoding.UTF8)
        Return reader.ReadToEnd()

    End Function

__________________
Paul Embry
Knight Software and Web Design
Paul.Embry@gmail.com
Quality PHP Web Programming for Reasonable Prices

Reply With Quote
  #5  
Old 05-12-2004, 03:29 PM
ACW ACW is offline
Aspiring Evangelist
 
Join Date: Jan 2004
Posts: 406
Sorry, we tried with no luck.
I'll see if I try again on my spare time.

Reply With Quote
  #6  
Old 05-12-2004, 03:38 PM
stormraven stormraven is offline
WHT Addict
 
Join Date: Apr 2004
Location: Port St Lucie, FL
Posts: 117
I finally got it - the working solution is not much different from the others, but it does involve buffering.

If anyone wants the final solution, send me a PM.

__________________
Paul Embry
Knight Software and Web Design
Paul.Embry@gmail.com
Quality PHP Web Programming for Reasonable Prices

Reply With Quote
  #7  
Old 05-13-2004, 09:14 AM
ACW ACW is offline
Aspiring Evangelist
 
Join Date: Jan 2004
Posts: 406
Quote:
Originally posted by stormraven
I finally got it - the working solution is not much different from the others, but it does involve buffering.

If anyone wants the final solution, send me a PM.
I'm glad you got it working. We had done similar things in the past but would write to the file system - not a browser. We were playing with the buffering when we had to stop.

Please PM me the final solution.

Thanks!

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Stream Data Centers Names VP of Marketing and Business Development Web Hosting News 2012-10-03 09:35:48
Colocation Operator Stream Data Centers Names VP of Project Management Web Hosting News 2012-09-13 15:57:33
Stream Data Centers Completes Dallas-Area Private Data Center Web Hosting News 2012-08-03 14:09:44
Stream Data Centers Acquires Land for New Facility in Texas Web Hosting News 2012-01-12 11:21:59
Stream Data Centers Names VP of Mission Critical Advisory Services Web Hosting News 2011-10-12 14:25:13


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?