Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to check for 404 without throwing an exception?

Posted on 2006-07-18
4
Medium Priority
?
714 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 600 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Integration Management Part 2
Suggested Courses

927 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