Nella mia classe ApiController, ho il seguente metodo per scaricare un file creato dal server.
public HttpResponseMessage Get(int id)
{
try
{
string dir = HttpContext.Current.Server.MapPath("~"); //location of the template file
Stream file = new MemoryStream();
Stream result = _service.GetMyForm(id, dir, file);
if (result == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
result.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.Content = new StreamContent(result);
return response;
}
catch (IOException)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError);
}
}
Tutto funziona perfettamente, tranne che il nome del file di download predefinito è il suo ID, quindi l'utente potrebbe dover digitare il proprio nome di file al momento del salvataggio come finestra di dialogo ogni volta. C'è un modo per impostare un nome file predefinito nel codice sopra?