Tim,
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
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
No, it didn't work. Here is the original code I have:
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
--------------------------------------------------------------------------------------------------
Tim Mackey wrote:
hi gary,
you may be missing a 'Content-Disposition' http header to specify the
filename. here is what i use, it works for me with the correct
filename:
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
I have aspnet code (C#) to create a Crystal Report and export to pdf
(in browser) without a Crystal Report Viewer.
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