473,408 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

webrequest help

hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 14 '08 #1
8 1895
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:BF**********************************@microsof t.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 14 '08 #2
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:BF**********************************@microsof t.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar

Oct 15 '08 #3
rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it
my web page?
You read the stream into a byte array, and then output the byte array into
the Response object. For a previous project, I found that adding a
content-disposition header helped (for Safari, I think).

.... your previous code ...
Stream Answer = WebResp.GetResponseStream();

int PdfByteCount = (int)Answer.Length - 1;
byte[] pdfBytes = new byte[PdfByteCount];
Answer.Read(pdfBytes, 0, PdfByteCount);

Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader(
"Content-disposition",
"inline; filename=some_file_name.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdfBytes);
Response.End();

--
Ben
http://allben.net/

Oct 15 '08 #4
Ben Amada wrote:
int PdfByteCount = (int)Answer.Length - 1;
byte[] pdfBytes = new byte[PdfByteCount];
Answer.Read(pdfBytes, 0, PdfByteCount);
That's not correct, should be:

byte[] pdfBytes = new byte[Answer.Length];
Answer.Read(pdfBytes, 0, (int)Answer.Length);

Oct 15 '08 #5
a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
>When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:BF**********************************@microso ft.com...
>>hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 15 '08 #6
i'm getting message:
This stream does not support seek operations.

Here's some of what i'm doing at the source of the url:

context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = @"application/pdf";
//context.Response.AddHeader("content-disposition",
String.Format("inline; filename={0}.pdf", adNumber));
context.Response.AddHeader("content-disposition",
String.Format("attachment; filename={0}.pdf", adNumber));

byte[] image = new byte[fileInfo.Length];
using (BinaryReader reader = new BinaryReader(new
FileStream(path, FileMode.Open, FileAccess.Read)))
{
image = reader.ReadBytes((int)fileInfo.Length);
}

context.Response.BinaryWrite(image);
context.Response.Flush();
context.Response.Close();
context.Response.End();
"bruce barker" wrote:
a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:
When you stream directly to the stream, you have to set the MIME type in the
page before the code that starts the stream. Once you have set the type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the website
and redirect the user to that file. Just make sure you have a mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:BF**********************************@microsof t.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 15 '08 #7
thanks everyone for the help,
rod.

"rodchar" wrote:
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to display on
my web page?

thanks,
rodchar
Oct 16 '08 #8
You can move data from a stream to another stream. Outputting as bytes is
another option, per Ben's post (have not gone through his code yet to ensure
it is correct).

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:CC**********************************@microsof t.com...
i'm getting message:
This stream does not support seek operations.

Here's some of what i'm doing at the source of the url:

context.Response.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = @"application/pdf";
//context.Response.AddHeader("content-disposition",
String.Format("inline; filename={0}.pdf", adNumber));
context.Response.AddHeader("content-disposition",
String.Format("attachment; filename={0}.pdf", adNumber));

byte[] image = new byte[fileInfo.Length];
using (BinaryReader reader = new BinaryReader(new
FileStream(path, FileMode.Open, FileAccess.Read)))
{
image = reader.ReadBytes((int)fileInfo.Length);
}

context.Response.BinaryWrite(image);
context.Response.Flush();
context.Response.Close();
context.Response.End();
"bruce barker" wrote:
>a pdf is webrequest response. it will replace the page with the pdf.
normally, you would have a link the user hits that returns the pdf file.
if you want it inline in the page, then you add an iframe to page, and
set the resource the pdf url.

-- bruce (sqlwork.com)

rodchar wrote:
once i set the MIME type, how, then, do i take the stream and display
it my
web page?

"Cowboy (Gregory A. Beamer)" wrote:

When you stream directly to the stream, you have to set the MIME type
in the
page before the code that starts the stream. Once you have set the
type, the
browser should recongnize the file as whatever type you have told the
browser that file is.

If that is overbearing, you can stream the file to a folder in the
website
and redirect the user to that file. Just make sure you have a
mechanism that
cleans up old files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:BF**********************************@microso ft.com...
hi all,

given:
HttpWebRequest WebReq =
(HttpWebRequest)WebRequest.Create("myurl");
WebReq.Method = "GET";
HttpWebResponse WebResp =
(HttpWebResponse)WebReq.GetResponse();
Response.Write(WebResp.StatusCode);
Response.Write(WebResp.Server);

Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);

this url is retrieving a .pdf file. how do i get my pdf file to
display on
my web page?

thanks,
rodchar
Oct 16 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Selbee | last post by:
I am trying to submit data to a webpage in the form of a post and my code is below. It is a function that takes a url and the post content as strings and then performs the post. But as soon as I...
17
by: James Johnson | last post by:
Dear C#dex, I define a variable: HttpWebRequest webRequest and run the following request webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest; The webRequest object returns values...
4
by: Paul | last post by:
Hello, I tried to execute a button on an aspx webpage using WebRequest, but it failed. When posting data as if I did a login (see code), I just receive the login page, instead of the page I...
8
by: John K. | last post by:
Hi I was wondering if it's possible to use the WebRequest class to access a file on windows shared folder with authentication? If yes, what would the syntax be? I've tried to look this up in the...
12
by: ThyRock | last post by:
I am working on a WebRequest accessing the US Postal Service WebTools test API. This service uses a DLL file (ShippingAPITest.dll) with a query string which includes XML. The web service accepts...
0
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
3
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I'm trying to create a call to a web page to validate and register software. The code I'm using is: Private Sub OK_Click(ByVal sender As...
0
by: buccsailor | last post by:
Hell there, I tried to post a reply to a message thread created back in July 2006 regarding the override of WebRequest, Closed Conenctions and setting KeepAlive to false,but it's been over 60...
3
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.