Solved

How to check for 404 without throwing an exception?

Posted on 2006-07-18
4
705 Views
Last Modified: 2008-01-09
I want to check for the availability of a file on a web server, using the .net framework. I can easily use a WebClient or WebRequest to attempt to get data from the URL, then catch the exception that is thrown if the requested file doesn't exist.

But I want to perform this check without exceptions - I don't like using exceptions to control program flow. Is there a way to get the headers back from the web server and check them myself, or to tell some framework class to just get me the data and ignore the 404 indication in the header?
0
Comment
Question by:jgr4
4 Comments
 
LVL 1

Accepted Solution

by:
winsoftech earned 200 total points
ID: 17143803
u can use xmlhttp method to call the page
using xmlhttp.open(url,'','')
this will rerutn status (xmlhttp.status)
if page is not present then it will return 404

u can use this to check for 404 without throwing an exception

it's not complete code u have to find on xmlhttp
0
 
LVL 3

Expert Comment

by:HouseMusic
ID: 17150181
You can use the custom errors section of your web.config to redirect them to a specific error page for that error (i.e. errorpage.aspx) and handle it in that "errorpage.aspx"

0
 
LVL 2

Author Comment

by:jgr4
ID: 17151167
winsoftech - that's a good hint and I'll give you the points if nothing better comes along, but I'm really looking for a way to do this from inside the .NET framework. I'm doing this from what will be a freeware app and I don't want to deal with versioning issues.

HouseMusic - I'm the client, not the server. This is a windows app looking for files on other people's webservers.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question