Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
929 views
in Technique[技术] by (71.8m points)

.net - How to display a Reporting Services report as an inline PDF, in a ASP.Net and C# web page?

I need to display a preview of a report, in an ASP.Net web page (using C# server side scripts). The preview needs to be a PDF rather than HTML and displayed inline (possibly in an iframe?).

Is it possible to specify the headers of a report rendered as a PDF, so its 'Content-Disposition' is inline rather than attachment?

Or is there any other way to display a report rendered as a PDF inline in an ASP.Net web page?


I am using Reporting Services 2008

In the ASP.Net site I am using web references to ReportService2005.asmx and ReportExecution2005.asmx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm doing something that is very similar. But I'm using a HttpWebRequest instead of using the service. Here's how I'm doing it. The important part is the inline before the file name in the Content-Disposition.

It also depends on their version of Adobe Reader (we found they need 7 or upwards) and the settings they have set inside it (in case they've set it to not open PDFs inside the browser).

HttpResponse currentResponse = HttpContext.Current.Response;
currentResponse.Clear();
currentResponse.ClearHeaders();
currentResponse.ClearContent();

filename = String.Format("{0}.pdf", this.ReportName);
currentResponse.AppendHeader("Content-Disposition", String.Format("inline;filename={0}", filename));
currentResponse.ContentType = "Application/PDF";

//Copy the content of the response to the 
//current response using BinaryWrite
snip....

currentResponse.End();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...