ReportViewer for WPF and Silverlight | ComponentOne
C1ReportViewer Task-Based Help / Loading Documents into C1ReportViewer
In This Topic
    Loading Documents into C1ReportViewer
    In This Topic

    If you run the application after adding a C1ReportViewer control to your application, you'll see an empty C1ReportViewer on the page. The next step is to invoke the LoadDocument method to add some content to the control. The LoadDocument method allows you to load content from Stream objects (which may contain PDF, HTML, or MHTML documents), or from strings (which may contain HTML or MHTML documents).

    You can easily load a document from an application resource. For example, complete the following steps:

    1. Navigate to the Solution Explorer, right-click the project name, and select Add │ Existing Item.
    2. In the Add Existing Item dialog box, locate a PDF file. In the file type drop-down box, you may need to choose All Files to view the PDF file. Note that if you choose, you can instead pick another PDF file to use.
    3. In the Solution Explorer, click the PDF file you just added to the application (in this example, we'll assume the file is named resource.pdf). In the Properties window, set its BuildAction property to Resource and confirm that the Copy to Output Directory item is set to Do not Copy.
    4. Switch to Code view by right-clicking the page and selecting View Code. In the next steps you'll add XAML markup to your application to add content to the drop-down box.
    5. Add the following imports statement at the top of the page:

       

      Visual Basic
      Copy Code
      Imports C1.WPF.ReportViewer
      

       

      C#
      Copy Code
      using C1.WPF.ReportViewer;
      
    6. Add the following code to the main class:

       

      Visual Basic
      Copy Code
      Public Sub New()
          InitializeComponent()
          Dim resource = Application.GetResourceStream(New Uri("AppName;component/resource.pdf", UriKind.Relative))
      Me.C1ReportViewer1.LoadDocument(resource.Stream)
      End Sub
      

       

      C#
      Copy Code
      public MainPage()
      {
          InitializeComponent();
          var uri = new Uri("/AppName;component/resource.pdf", UriKind.Relative);
          var resource = Application.GetResourceStream(uri);
          this.C1ReportViewer1.LoadDocument(resource.Stream);
      }
      

    This code adds a stream and loads the stream into the C1ReportViewer control. Note that if you named the application differently, you will need to replace "AppName" with the name of your project. If you added a different PDF file, replace "resource.pdf" with the name of your file.

    See Also