Forum Moderators: open
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.yahoo.com/image.gif");
req.AllowAutoRedirect = false; // In case the server is configured to redirect on 404
try
{
// Get response from the server
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
// Check response code
if(res.StatusCode == HttpStatusCode.OK)
System.Diagnostics.Debug.WriteLine("File is accessable");
else
System.Diagnostics.Debug.WriteLine("File is not accessable");
}
catch(WebException ex)
{
// Handle DSN error.
System.Diagnostics.Debug.WriteLine("Name resolution error: " + ex.ToString());
}