HI.
How to check File exists in Web Share C#
[code=c#]
try
{
WebRequest request = HttpWebRequest. Create("http://www.microsoft.c om/NonExistantFile .aspx");
request.Method = "HEAD"; // Just get the document headers, not the data.
request.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
// This may throw a WebException:
using (HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse())
{
if (response.Statu sCode == HttpStatusCode. OK)
{
// If no exception was thrown until now, the file exists and we
// are allowed to read it.
MessageBox.Show ("The file exists!");
}
else
{
// Some other HTTP response - probably not good.
// Check its StatusCode and handle it.
}
}
}
catch (WebException ex)
{
// Cast the WebResponse so we can check the StatusCode property
HttpWebResponse webResponse = (HttpWebRespons e)ex.Response;
// Determine the cause of the exception, was it 404?
if (webResponse.St atusCode == HttpStatusCode. NotFound)
{
MessageBox.Show ("The file does not exist!");
}
else
{
// Handle differently...
MessageBox.Show (ex.Message);
}
}
[/code]
i try this above but excpection is thrown while excuting the following Code
using (HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse())
please Help me
Thanks in Advance
With Regards,
Mani
How to check File exists in Web Share C#
[code=c#]
try
{
WebRequest request = HttpWebRequest. Create("http://www.microsoft.c om/NonExistantFile .aspx");
request.Method = "HEAD"; // Just get the document headers, not the data.
request.Credent ials = System.Net.Cred entialCache.Def aultCredentials ;
// This may throw a WebException:
using (HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse())
{
if (response.Statu sCode == HttpStatusCode. OK)
{
// If no exception was thrown until now, the file exists and we
// are allowed to read it.
MessageBox.Show ("The file exists!");
}
else
{
// Some other HTTP response - probably not good.
// Check its StatusCode and handle it.
}
}
}
catch (WebException ex)
{
// Cast the WebResponse so we can check the StatusCode property
HttpWebResponse webResponse = (HttpWebRespons e)ex.Response;
// Determine the cause of the exception, was it 404?
if (webResponse.St atusCode == HttpStatusCode. NotFound)
{
MessageBox.Show ("The file does not exist!");
}
else
{
// Handle differently...
MessageBox.Show (ex.Message);
}
}
[/code]
i try this above but excpection is thrown while excuting the following Code
using (HttpWebRespons e response = (HttpWebRespons e)request.GetRe sponse())
please Help me
Thanks in Advance
With Regards,
Mani
Comment