Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't compile - Request.Content.IsMimeMultipartContent() not found

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?

like image 354
Oleg Sh Avatar asked Jul 09 '13 17:07

Oleg Sh


1 Answers

Add the following reference:

"using System.Net.Http;"

{}'s

like image 155
Rodrigo Reis Avatar answered Sep 28 '22 07:09

Rodrigo Reis