ApiController sınıfımda, sunucu tarafından oluşturulan bir dosyayı indirmek için aşağıdaki yöntemi var.
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);
}
}
Varsayılan indirme dosya adının kimliği olması dışında her şey mükemmel çalışıyor, böylece kullanıcı her seferinde kaydet iletişim kutusunda kendi dosya adını yazmak zorunda kalabilir. Yukarıdaki kodda varsayılan bir dosya adı ayarlamanın bir yolu var mı?