Forum Moderators: open

Message Too Old, No Replies

Can i detect if a file on another web site exist?

Can httpRequest help me with this?

         

FwAnK

8:55 pm on Aug 1, 2002 (gmt 0)

10+ Year Member




I want the user to send me the url to an image but i'd like to check if it exist.

How can i do this in asp.net?

Thank-you,

threecrans

1:28 pm on Aug 2, 2002 (gmt 0)

10+ Year Member



HttpRequest seems like a good way to me. The following code worked fine here (although it CERTAINLY could be made more robust).


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());
}