public bool RemoveFile(string fileUrl, string fileName)
{
string fullFileUri = string.Format("{0}/{1}", fileUrl, fileName);
HttpWebRequest deleteRequest = HttpWebRequest.Create(fullFileUri) as HttpWebRequest;
HttpWebResponse response = null;
try
{
if (fullFileUri.StartsWith("HTTPS", System.StringComparison.OrdinalIgnoreCase))
{
Common.Common.AcceptServerCertificate();
}
deleteRequest.Credentials = new NetworkCredential(Common.Common.GetConfigurationPropertyValue("UserName1", Site), Common.Common.GetConfigurationPropertyValue("Password1", Site), Common.Common.GetConfigurationPropertyValue("Domain", Site));
deleteRequest.Method = "DELETE";
response = deleteRequest.GetResponse() as HttpWebResponse;
return response.StatusCode == HttpStatusCode.NoContent || response.StatusCode == HttpStatusCode.OK;
}
catch (System.Net.WebException ex)
{
Site.Log.Add(
LogEntryKind.Debug,
string.Format("Cannot delete the file in the full URI {0}, the exception message is {1}", fullFileUri, ex.Message));
return false;
}
finally
{
// Close the connection before returning.
if (response != null)
{
response.Close();
}
}
}
}