Ho il seguente codice:non può compilare - Request.Content.IsMimeMultipartContent() non trovato
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"));
}
}
}
ma ho ottenuto errori:
errore 16 'System.Net.Http. HttpContent 'non contiene una definizione per' IsMimeMultipartContent 'e nessun metodo di estensione ' IsMimeMultipartContent 'che accetta un primo argomento di tipo ' System.Net.HttpHttpContent 'potrebbe essere trovato (manca una direttiva o un assembly ri Ference?)
Errore 17 'System.Net.Http.HttpContent' non contiene una definizione per 'ReadAsMultipartAsync' e nessun metodo di estensione 'ReadAsMultipartAsync' accettare un primo argomento di tipo 'System.Net.Http. HttpContent 'stato trovato (che le manca una direttiva using o un riferimento all'assembly?)
Errore 18 'System.Net.Http.HttpRequestMessage' non contiene una definizione per 'CreateResponse' e nessun metodo di estensione ' CreateResponse 'accettando un primo argomento di tipo ' System.Net.Http.HttpRequestMessage 'potrebbe essere trovato (sei sbagliato cantare un utilizzando direttiva o un riferimento di assembly?)
perché? ho aggiunto per proiettare System.Net.Http.Formatting.dll assemblaggio e hanno
using System.Net.Http.Formatting;
a pagina http://msdn.microsoft.com/ru-ru/library/hh834190(v=vs.108).aspx attentamente detto, che questo ext. metodo è in System.Net.Http.Formatting (in System.Net.Http.Formatting.dll) Ho provato a compilare il progetto in 4.0 e 4.5 - nessun effetto.
PS. Ho una soluzione con lo stesso codice, che funziona perfettamente. Cosa posso fare?
La pagina di MSDN si collega a mostra nella System.Net.Http' namespace '{}. Ti manca una dichiarazione using? –
grazie! Errore davvero stupido, l'ho controllato due volte, ma ho perso in ogni caso ... –