Skip to content

Instantly share code, notes, and snippets.

@matijagrcic
Last active August 29, 2015 14:02
Show Gist options
  • Save matijagrcic/47208a43e6495baa60ba to your computer and use it in GitHub Desktop.
Save matijagrcic/47208a43e6495baa60ba to your computer and use it in GitHub Desktop.
public async Task<FileStreamResult> GenerateReport()
{
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(new Uri("http://domainORipaddress"), "NTLM", new NetworkCredential(
ConfigurationManager.AppSettings["username"],
ConfigurationManager.AppSettings["password"]
));
Stream report = null;
using (var httpClient = new HttpClient(new HttpClientHandler { Credentials = credentialCache }))
{
httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
report = await httpClient.GetStreamAsync("reportUrl");
}
var contentDisposition = new ContentDisposition
{
FileName = "Report.pdf",
Inline = false
};
Response.AppendHeader("Content-Disposition", contentDisposition.ToString());
return File(report, "application/pdf");
//or use
//Response.AppendHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", reportName));
//return File(reportPath, MediaTypeNames.Application.Pdf);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment