How to detect missing page or object from code

  • Thread starter Thread starter pamela fluente
  • Start date Start date
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
 
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).
 
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
 
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
 
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
 
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
 
Back
Top