Microsoft.Protocols.TestSuites.SharedAdapter.MS_FSSHTTP_FSSHTTPBManagedCodeSUTControlAdapter.RemoveFile C# (CSharp) Method

RemoveFile() public method

This method is used to remove the file from the path of file URI.
public RemoveFile ( string fileUrl, string fileName ) : bool
fileUrl string Specify the URL in where the file will be removed.
fileName string Specify the name for the file that will be removed.
return bool
        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();
                }
            }
        }
    }
MS_FSSHTTP_FSSHTTPBManagedCodeSUTControlAdapter