Solved

How to check for 404 without throwing an exception?

Posted on 2006-07-18
4
701 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now