无法编译 - 找不到Request.Content.IsMimeMultipartContent()

时间:2013-07-09 17:55:31

标签: asynchronous system.net

我有以下代码:

   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"));
        }

    }
}

但我收到了错误:

  

错误16'System.Net.Http.HttpContent'不包含定义   'IsMimeMultipartContent'并没有扩展方法   'IsMimeMultipartContent'接受第一个类型的参数   可以找到'System.Net.Http.HttpContent'(你错过了使用   指令或程序集引用?)

     

错误17'System.Net.Http.HttpContent'不包含定义   对于'ReadAsMultipartAsync'而没有扩展方法   'ReadAsMultipartAsync'接受类型的第一个参数   可以找到'System.Net.Http.HttpContent'(你错过了使用   指令或程序集引用?)

     

错误18'System.Net.Http.HttpRequestMessage'不包含   'CreateResponse'的定义,没有扩展方法   'CreateResponse'接受第一个类型的参数   可以找到'System.Net.Http.HttpRequestMessage'(你错过了吗?   使用指令或程序集引用?)

为什么呢? 我添加了一个程序集System.Net.Http.Formatting.dll并且有

using System.Net.Http.Formatting;
http://msdn.microsoft.com/ru-ru/library/hh834190(v=vs.108).aspx页上的

仔细说,这个分​​机。方法在System.Net.Http.Formatting中(在System.Net.Http.Formatting.dll中) 我试图在4.0和4.5下编译项目 - 没有效果。

PS。我有一个使用相同代码的解决方案,它完美地运行。我该怎么办?

1 个答案:

答案 0 :(得分:8)

添加以下参考:

&#34;使用System.Net.Http;&#34;

{}&#39; S