Works great except when the user attempts to save the file from the
browser. In the "Save a copy ..." dialog box the filename defaults to
the name of aspx page. I need it to default to a custom report name.
How can I specify the new file name in aspnet and pass it to the new
PDF page?
Thanks for the help,
Gary
public static void
ExportCrystalReportToPDF(CrystalDecisions.CrystalReports.Engine.ReportClass
rpt, string filename)
{
MemoryStream stream =
(MemoryStream)rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byte[] bytes = new Byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
stream.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer= true;
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "inline;filename=\"" + filename
+ "\"");
response.BinaryWrite(bytes);
response.End();
}
hope this helps
tim
<glb...@yahoo.com> wrote in message
news:1169051724.1...@v45g2000cwv.googlegroups.com...
- Gary
------------------------------
HttpResponse oResponse = HttpContext.Current.Response;
oResponse.ClearContent();
oResponse.ClearHeaders();
oResponse.ContentType = "application/pdf";
oResponse.WriteFile(sOutFile.ToString().Trim());
oResponse.Flush();
oResponse.Close();
// ***** sOutFile = name of pdf file being read and output into the
browser. ***///
- Gary
--------------------------------------------------------------------------------------------------
<glb...@yahoo.com> wrote in message
news:1169058682....@38g2000cwa.googlegroups.com...
Thanks for keeping on top of this problem, it's appreciated. Okay,
here is the code I have:
FileStream stream = new FileStream(sOutFile, FileMode.OpenOrCreate,
FileAccess.Read );
byte[] bytes = new Byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
stream.Close();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AppendHeader("Content-Disposition",
"attachment;filename=myfilename.pdf");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();
It opens the file as an attachment and asks the user if they want to
"save" or "open". It passes the correct file name. I thought that
would suffice, but found out this morning that it won't. They
(customer) want it to open into a browser and if the user decides to
save it, the name of the report (plus a time stamp) should default into
the "filename" area of the "Save a copy ..." dialog box. I tried the
"inline" and several other code changes that someone suggested but it
did not work, it keeps sending the aspx page name with ".pdf" tacked
onto it.
What am I doing wrong?
- Gary
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
<html>
<body marginwidth="0" marginheight="0">
<embed width="100%" height="100%" name="plugin"
src="http://localhost:63106/Default.aspx" type="application/pdf"/>
</body>
</html>
at least for firefox, it creates a html page to embed the pdf. perhaps IE
does the same thing. as you can see, there is no specification here of the
correct file name.
when you open the pdf directly, e.g. drag it into a browser window, the same
wrapper html page is created, except it has the proper filename, then when
you save in Acrobat, it gets the name of the file right.
what i suggest (and what i do in my apps) is to save the PDF file to a temp
folder within the web site, and just do a Response.Redirect to the pdf file.
it displays inline, and it will retain the correct filename. i run a script
every night on the server to clear out the temp folder.
hope this helps
tim
<glb...@yahoo.com> wrote in message
news:1169124821.1...@38g2000cwa.googlegroups.com...
Thanks for all your help!
- Gary