【发布时间】:2013-07-09 17:55:30
【问题描述】:
我有以下代码:
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。我有一个使用相同代码的解决方案,效果很好。我能做什么?
【问题讨论】:
-
您链接到的 MSDN 页面在
System.Net.Http命名空间中显示它。您是否缺少 using 语句? -
谢谢!真是愚蠢的错误,我检查了两次,但无论如何都输了......