Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shiranGinige/7173740 to your computer and use it in GitHub Desktop.
Save shiranGinige/7173740 to your computer and use it in GitHub Desktop.
I just want to save a file temporarily and return it as a stream for a HTTP response. Azure don't like me writing things to the file system? Here's how to get around.
var data = getData();
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Header");
foreach (var item in data)
{
stringBuilder.AppendLine(data.Stuff)
}
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(stringBuilder.ToString())));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "FileName";
return response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment