Last post Jan 10, 2007 03:36 AM by Zhao Ji Ma - MSFT
Jan 09, 2007 01:38 PM|digitallyskilled|LINK
Can anyone help me stream a PDF to a browser?
I want to retrieve a file over port 80 across our firewall and display the PDF on the webserver which is on the other side of the firewall.
I get the file name from a web service but now I want to open the file.
I have to use an http request because we dont want the tcp traffic from a file request going across the firewall.
I am able to get a text file accross but not succesfull in getting a PDF.
I know I have to use the context application/pdf.
I am not to familiar with streaming and the mechanics of requesting files over http so I am kind of stuck. from the examples that i have seen I think it is not too far from the example below which is how i got the text file across.
Any help would be appreciated. thanks
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://10.1.1.10/LocalFiles/1_2_nl3.txt");
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Response.Write("\r\nResponse stream received.");
Char read = new Char;
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
while (count > 0)
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
count = readStream.Read(read, 0, 256);
// Releases the resources of the response.
// Releases the resources of the Stream.
Jan 10, 2007 03:36 AM|Zhao Ji Ma - MSFT|LINK
try add http headers:
' set the content type to PDF
Response.ContentType = "application/pdf"
' add content type header
' set the content disposition