I am using below code which used to download SSRS report in pdf format:
string URL = "http://ssrs-test.com/ReportS/?/UAT_FOLDER";
URL = URL + "&SRNo=122&rs:Command=Render&rs:Format=pdf";
System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(URL);
Req.Method = "GET";
string path = @ "E:\New folder\Test.pdf";
System.Net.WebResponse objResponse = Req.GetResponse();
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
System.IO.Stream stream = objResponse.GetResponseStream();
byte[] buf = new byte[1024];
int len = stream.Read(buf, 0, 1024);
while (len > 0) {
fs.Write(buf, 0, len);
len = stream.Read(buf, 0, 1024);
}
stream.Close();
fs.Close();
Which perfectly creates a pdf file in the specified path E:\New folder\
, what I am trying to do is:
I need download it on browser as we were doing in the asp.net with Response.Write()
and Response.End()
etc.
Can I do the same in the ASP.Net Core?
What I tried:
return new PhysicalFileResult(@"with_samplepdf_file", "application/pdf"); -- Not worked
var stream = new FileStream(@"with_samplepdf_file", FileMode.Open);
return new FileStreamResult(stream, "application/pdf"); -- Not worked - Nothing happening on the browser
var file = @"with_samplepdf_file/pdf";
// Response...
System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
{
FileName = file,
Inline = displayInline // false = prompt the user for downloading; true = browser to try to show the file inline
};
Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("X-Content-Type-Options", "nosniff");
return File(System.IO.File.ReadAllBytes(file), "application/pdf");