We help IT Professionals succeed at work.

ASP.NET - Rewriting a file extension

686 Views
Last Modified: 2013-11-25
I have a page in my website that reads a crystal report and displays it as a PDF. Heres a little of the code...

            theReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            m = (System.IO.MemoryStream)theReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            theReport.Close();

            this.Response.ClearContent();
            this.Response.ClearHeaders();
            this.Response.AddHeader("Title", strFileName);
            this.Response.ContentType = "Application/pdf";
            this.Response.Buffer = true;
            this.Response.BinaryWrite(m.ToArray());
            this.Response.End();


I need the page (an aspx page) to be displayed as a .pdf page in the browser. The reason is that users on the site click the email page button and it trys to send a .aspx file as the attachment. Ive manually changed the file extension after emailing it to .pdf and it opens correctly, but people shouldn't have to do that. I need a rewriting technique to change it from .aspx to .pdf in the address bar of the browser. Any ideas?
Comment
Watch Question

Commented:
If I understand your questions correctly, try removing the following line

this.Rsponse.AddHeader("Tile", strFileName);

or change strFileName value to "filename.pdf

Author

Commented:
Thanks anyway, but that didn't work.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.