Вопрос

I have the following code:

   public class UploadController : ApiController
{
    DBRepository _repository = new DBRepository();


    public Task<IEnumerable<FileDesc>> Post()
    {
        string folderName = "UploadedFiles";
        string PATH = HttpContext.Current.Server.MapPath("~/" + folderName);
        PATH = @"c:\www\qqq";
        string rootUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.AbsolutePath, String.Empty);


        if (Request.Content.IsMimeMultipartContent())
        {
            var streamProvider = new CustomMultipartFormDataStreamProvider(PATH);

            var task = Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith<IEnumerable<FileDesc>>(t =>
            {

                if (t.IsFaulted || t.IsCanceled)
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }


                return fileInfo;
            });

            return task;
        }
        else
        {
            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"));
        }

    }
}

but I got errors:

Error 16 'System.Net.Http.HttpContent' does not contain a definition for 'IsMimeMultipartContent' and no extension method 'IsMimeMultipartContent' accepting a first argument of type 'System.Net.Http.HttpContent' could be found (are you missing a using directive or an assembly reference?)

Error 17 'System.Net.Http.HttpContent' does not contain a definition for 'ReadAsMultipartAsync' and no extension method 'ReadAsMultipartAsync' accepting a first argument of type 'System.Net.Http.HttpContent' could be found (are you missing a using directive or an assembly reference?)

Error 18 'System.Net.Http.HttpRequestMessage' does not contain a definition for 'CreateResponse' and no extension method 'CreateResponse' accepting a first argument of type 'System.Net.Http.HttpRequestMessage' could be found (are you missing a using directive or an assembly reference?)

why? I added to project an assembly System.Net.Http.Formatting.dll and have

using System.Net.Http.Formatting;

on page http://msdn.microsoft.com/ru-ru/library/hh834190(v=vs.108).aspx carefully said, that this ext. method is in System.Net.Http.Formatting (in System.Net.Http.Formatting.dll) I tried to compile project under 4.0 and 4.5 - no effect.

PS. I have a solution with the same code, which works perfectly. What can I do?

Это было полезно?

Решение

Add the following reference:

"using System.Net.Http;"

{}'s

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top