本文整理汇总了C#中System.Net.Http.MultipartFormDataContent.GetUploadFileErrorMesage方法的典型用法代码示例。如果您正苦于以下问题:C# MultipartFormDataContent.GetUploadFileErrorMesage方法的具体用法?C# MultipartFormDataContent.GetUploadFileErrorMesage怎么用?C# MultipartFormDataContent.GetUploadFileErrorMesage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.MultipartFormDataContent
的用法示例。
在下文中一共展示了MultipartFormDataContent.GetUploadFileErrorMesage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFile
/// <summary>
/// Upload file
/// </summary>
/// <returns>Awaitable task object</returns>
private static async Task UploadFile()
{
try
{
string uploadRequestURI = "uploadasync?overWrite=true";
MultipartFormDataContent formDataContent = new MultipartFormDataContent();
// Validate the file and add to MultipartFormDataContent object
formDataContent.AddUploadFile(@"c:\nophoto.png");
formDataContent.AddUploadFile(@"c:\ReadMe.txt");
// Add more file
if (!formDataContent.HasContent()) // No files found to be uploaded
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(formDataContent.GetUploadFileErrorMesage());
return;
}
else
{
string uploadErrorMessage = formDataContent.GetUploadFileErrorMesage();
if (!string.IsNullOrWhiteSpace(uploadErrorMessage)) // Some files couldn't be found
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(uploadErrorMessage);
}
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uploadRequestURI);
request.Content = formDataContent;
using (HttpClient httpClient = new HttpClient())
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(string.Format("Start uploading @ {0}, {1} time ",
DateTime.Now.ToLongDateString(),
DateTime.Now.ToLongTimeString()));
httpClient.BaseAddress = baseStreamingURL;
await httpClient.SendAsync(request).
ContinueWith((response)
=>
{
try
{
ProcessUploadResponse(response);
}
catch (AggregateException aggregateException)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(string.Format("Exception : ", aggregateException));
}
});
}
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(ex.Message);
}
}