Apparently, I don't understand how to use the ContinueWith method. My goal is to complete the task, and when it is completed, return the message.
Here is my code:
public string UploadFile()
{
if (Request.Content.IsMimeMultipartContent())
{
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Files"));
Task<IEnumerable<HttpContent>> task = Request.Content.ReadAsMultipartAsync(provider);
string filename = "Not set";
task.ContinueWith(o =>
{
filename = provider.BodyPartFileNames.First().Value;
}, TaskScheduler.FromCurrentSynchronizationContext());
return filename;
}
else
{
return "Invalid.";
}
}
The variable "filename" always returns "Not set." It seems that the code inside the ContinueWith method is never called. (It gets called if I debug it line by line in VS.)
This method is called in my ASP.NET/Ajax POST API.
What am I doing wrong here?
Rivka source
share