mounika madhavaram

mounika madhavaram

  • NA
  • 42
  • 10.7k

In upload docume method I need to use web client class

Sep 18 2018 4:43 AM
how to Use web client class in UploadDocuments(upload file) method in wpf..
( ObservableCollection Documents)  i have selected files.
private void UploadDocuments(ObservableCollection Documents)
{
HttpRequestMessage message = new HttpRequestMessage();
MultipartFormDataContent content = new MultipartFormDataContent();
content.Add(new StringContent(JsonConvert.SerializeObject(Documents)), "seriliazedContent");
foreach (var item in Documents)
{
FileStream filestream = new FileStream(item.Path, FileMode.Open, FileAccess.Read);
content.Add(new StreamContent(filestream), "file", item.OriginalFileName);
}
message.Method = HttpMethod.Post;
message.Content = content;
message.RequestUri = new Uri(ProHelper.GetProMoveServer() + "api/Utility/uploaddocuments");
var client = HttpClientFactory.Create();
client.SendAsync(message).ContinueWith(task =>
{
var response = task.Result.Content.ReadAsStringAsync();
var json = JsonConvert.DeserializeObject>(response.Result);
});
}
 
Can any one suggest....