Skip to content

Instantly share code, notes, and snippets.

@mattcanty
Created October 30, 2014 16:28
Show Gist options
  • Save mattcanty/43f4f4bc73d9441b6e81 to your computer and use it in GitHub Desktop.
Save mattcanty/43f4f4bc73d9441b6e81 to your computer and use it in GitHub Desktop.
Download from web service as an attachment
private static HttpResponseMessage DownloadResponse(string content, string fileName)
{
var downloadContent = new StringContent(content);
var mediaType = new MediaTypeHeaderValue("application/octet-stream");
var dispostition = new ContentDispositionHeaderValue("attachment") { FileName = fileName };
downloadContent.Headers.ContentType = mediaType;
downloadContent.Headers.ContentDisposition = dispostition;
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = downloadContent
};
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment