How to detect missing page or object from code

P

pamela fluente

I have placed a button on a page to open a pdf stored on another
site.

When the user clicks on the button I do a Redirect to the pdf URL
.... and this seems to work fine.

Question: is this the best way to do that ?

In case the PDF file, http://My.server.com/MyPdf.pdf is not on the
server
how can I detect this condition within the program and inform the
user, instead of letting
him to receive an error page ?

-P
 
P

Patrice

You could use System.net.WebClient to send HTTP requests to this third party
server (possibly using a HEAD request at a lower level if you want just to
check for the presence of this file wihtout downloading it).
 
K

Kevin Spencer

Create an internediate ASPX page that is returned. The intermediate page
would use an HttpRequest to attempt to download the PDF file. If it gets
back a 404 status code, it returns a regular HTML response indicating that
the file is not found, or whatever you wish to say. Otherwise, it sets the
Response.ContentType to "application/pdf" and uses Response.BinaryWrite to
write the PDF file back to the client browser.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
P

pamela fluente

You could use System.net.WebClient to send HTTP requests to this third party
server (possibly using a HEAD request at a lower level if you want just to
check for the presence of this file wihtout downloading it).

---
Patrice

"pamela fluente" <[email protected]> a écrit dans le message de (e-mail address removed)...










- Mostra testo tra virgolette -

Do you have a simple snippet of this procedure?

Thank you.

-P
 
P

Patrice

Try :

http://msdn2.microsoft.com/en-us/library/ez801hhe.aspx to download the whole
file (and scroll down to the code samples that shows how to download a gif
file from a web site). Is it me or is MSDN slow ?

Or :
http://www.eggheadcafe.com/tutorial...9-f82f59991517/the-lowly-http-head-reque.aspx
if you want just to check that the file is still available

http://en.wikipedia.org/wiki/Http#Request_methods discusses the various HTTP
method (basically GET gets the whole content, while HEAD will just retrieve
the header).

---
Patrice


"pamela fluente" <[email protected]> a écrit dans le message de
(e-mail address removed)...
You could use System.net.WebClient to send HTTP requests to this third
party
server (possibly using a HEAD request at a lower level if you want just to
check for the presence of this file wihtout downloading it).

---
Patrice

"pamela fluente" <[email protected]> a écrit dans le message de
(e-mail address removed)...










- Mostra testo tra virgolette -

Do you have a simple snippet of this procedure?

Thank you.

-P
 
P

pamela fluente

Try :

http://msdn2.microsoft.com/en-us/library/ez801hhe.aspxto download the whole
file (and scroll down to the code samples that shows how to download a gif
file from a web site). Is it me or is MSDN slow ?

Or :http://www.eggheadcafe.com/tutorials/aspnet/2c13cafc-be1c-4dd8-9129-f....
if you want just to check that the file is still available

http://en.wikipedia.org/wiki/Http#Request_methodsdiscusses the various HTTP
method (basically GET gets the whole content, while HEAD will just retrieve
the header).

---
Patrice

"pamela fluente" <[email protected]> a écrit dans le message de (e-mail address removed)...



Do you have a simple snippet of this procedure?

Thank you.

-P- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

Thanks a lot!

-P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top