public HttpResponseMessage Get(int id)
{
try
{
string filename = "File.pdf";
string filepath = System.Web.HttpContext.Current.Server.MapPath("~") + "/" + filename;
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(filedata); ;
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(filepath));
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true,
};
HttpContext.Current.Response.Headers.Add("Content-Disposition", cd.ToString());
return result;
}
catch (Exception)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
No comments:
Post a Comment