The requested page is not available for the requested platform. You are viewing the content for Default platform.

Add the Document Viewer to an ASP.NET WebForms Application

  • 2 min to read
Note

Watch the Video: Reporting: Web Viewer (YouTube)

This tutorial demonstrates how to add the Document Viewer to a web page in an ASP.NET WebForms application:

  1. In Visual Studio, open an existing application or create a new one from scratch.
  2. Expand the DX.19.1: Reporting Toolbox tab and drop the ASPxWebDocumentViewer control onto the page.

    drop-control-document-viewer-web-page

  3. Assign a report to the Document Viewer by clicking the control's smart tag, expanding the drop-down list for the Report property and selecting your report.

    aspx-web-doc-viewer-set-report

    You can also open a report in code using the ASPxWebDocumentViewer.OpenReport or ASPxWebDocumentViewer.OpenReportXmlLayout method.

    using DevExpress.XtraReports.Web;
    //...
        protected void Page_Load(object sender, EventArgs e)
        {
            var cachedReportSource = new CachedReportSourceWeb(new XtraReport1());
            ASPxWebDocumentViewer1.OpenReport(cachedReportSource);
        }
    

    In this code, the CachedReportSourceWeb object passed as the OpenReport method's parameter generates a document for the associated report, caching each generated page.

  4. Add the "resources" section to the application's Web.config file as shown below to transfer all the necessary script files to a client application automatically.

    <devExpress>
        <!-- ... -->
        <resources>
            <add type="ThirdParty" />
            <add type="DevExtreme" />
        </resources>
    </devExpress>
    

    Refer to the Document Viewer Requirements and Limitations to learn about manual Document Viewer integration.

  5. You can enable the Document Viewer to use an HttpContext (Session or User) by specifying the Session State property in the control's smart tag.

    This adds all necessary handlers to the application's Web.config file and registers them at the application startup in the Global.asax file.

    protected void Application_Start(object sender, System.EventArgs e) {
        DevExpress.XtraReports.Web.WebDocumentViewer.Native.WebDocumentViewerBootstrapper.SessionState = 
            System.Web.SessionState.SessionStateBehavior.Required;
    }
    
  6. You can customize the Web Document Viewer should you require.

Run the application to view the Document Viewer in a web browser.

get-started-web-document-viewer-result

See Also