Franck said:
i have already a way to know if a file is there by using
System.Net.WebRequest.Create(strURL);
the problem come when checking for huge file. How do i manage that.
because the code define over there read the entire file and output a
string in my case. Is there any other system.net object that could
check only if a file exist.
See code below for inspiration.
Arne
===============================================
public enum WebTestResult
{
STATUS_EXIST,
STATUS_NOT_EXIST,
STATUS_NO_HOST,
STATUS_NOT_HTTP
}
public class WebTest
{
public static WebTestResult Exist(string url)
{
try
{
WebRequest wreq = WebRequest.Create(url);
wreq.Method = "HEAD";
WebResponse wresp = wreq.GetResponse();
if(wresp is HttpWebResponse)
{
HttpWebResponse hwresp = (HttpWebResponse)wresp;
if(hwresp.StatusCode == HttpStatusCode.OK)
{
return WebTestResult.STATUS_EXIST;
}
else
{
return WebTestResult.STATUS_NOT_EXIST;
}
}
else
{
return WebTestResult.STATUS_NOT_HTTP;
}
}
catch(WebException wex)
{
if(wex.Response == null)
{
return WebTestResult.STATUS_NO_HOST;
}
else
{
if(wex.Response is HttpWebResponse)
{
HttpWebResponse hwresp =
(HttpWebResponse)wex.Response;
if(hwresp.StatusCode == HttpStatusCode.OK)
{
throw new SystemException("Should never happen");
}
else
{
return WebTestResult.STATUS_NOT_EXIST;
}
}
else
{
return WebTestResult.STATUS_NOT_HTTP;
}
}
}
}
}