private bool PutNewFileIntoServer(string destinationUri, string filePath)
{
if (string.IsNullOrEmpty(destinationUri))
{
return false;
}
if (string.IsNullOrEmpty(filePath))
{
return false;
}
bool isSuccessful = false;
// Get the file content based on the file path.
byte[] bytes = GetLocalFileContent(filePath);
// Construct the request headers.
NameValueCollection headersCollection = new NameValueCollection();
headersCollection.Clear();
headersCollection.Add("Cache-Control", "no-cache");
headersCollection.Add("ContentLength", bytes.Length.ToString());
headersCollection.Add("moss-cbfile", bytes.Length.ToString());
headersCollection.Add("ProtocolVersion", "HTTP/1.1");
// Call HTTP PUT method to upload the file into the destination URI.
WDVMODUUResponse response = this.Adapter.Put(destinationUri, bytes, headersCollection);
// Assert the response is successful.
Site.Assume.IsTrue(
response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created,
string.Format("Failed to PUT file {0} to the server under the path {1}! The return status code is {2}.", filePath, destinationUri, response.StatusCode));
if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
{
isSuccessful = true;
}
else
{
isSuccessful = false;
}
return isSuccessful;
}