Thanks,
//send metadata and file to the servlet
log.Debug("Create instance of WebClient");
WebClient client = new WebClient();
log.Debug("Get the securityToken");
String securityToken = SecurityToken.getToken();
log.Debug("SecurityToken is set to: " + securityToken);
log.Debug("Create a collection of values");
NameValueCollection querystring = setCollectionValues(m1, securityToken);
log.Debug("Create the postData which will include the securityToken and all metadata");
string postdata = "?";
if (querystring != null)
{
foreach (string key in querystring.Keys)
{
postdata += key + "=" + querystring.Get(key) + "&";
}
}
log.Debug("Create the uri and add the postdata.");
Uri uri = new Uri(url + postdata);
log.Debug("URI is: " + uri.ToString());
//Create streams for request /response
Stream data = null;
StreamReader reader = null;
//try to upload the file to the servlet
try
{
log.Debug("Try Upload file " + file + " to servlet at " + url);
client.UploadFile(uri, "POST", file);
data = client.OpenRead(url);
if (data != null)
{
log.Debug("Response returned from server.");
reader = new StreamReader(data);
saveStatus = reader.ReadToEnd();
Console.Write("Response From Server: " + saveStatus);
}
else
{
log.Debug("Error Accessing the saveServlet");
saveStatus = "Problem with Server. Try Again later";
}
log.Debug("Close the Streams");
reader.Close();
data.Close();
}
catch(WebException e)
{
log.Error("Error with accessing the server / servlet. Error returned is: " + e.Status);
saveStatus = "Error occured while trying to upload file to server." ;
}
}
else
{
log.Debug("Client side validation Failed.");
saveStatus = validationStatus;
log.Debug("Set the return String to the validationStatus: " + validationStatus);
}
Replies
Know the answer? Post it — somebody with the same question will find it here.