C1ReportViewer Task-Based Help > Loading Documents into C1ReportViewer > Loading Documents from Files on the Client Machine (Silverlight) |
In this example, you'll set up the application so that users can load a file from the local file system. You will add a button to the application and then add code to choose and open a file at run time. Because this example uses the OpenFileDialog control this code must be executed in a Button Click event. Note that this topic assumes you have added a C1ReportViewer control named "C1ReportViewer1" to your application.
Complete the following steps.
<Button Content="Load File" Height="23" Name="Button1" Width="70" Click="Button1_Click" />
Visual Basic |
Copy Code
|
---|---|
Imports C1.Silverlight.ReportViewer
|
C# |
Copy Code
|
---|---|
using C1.Silverlight.ReportViewer;
|
Visual Basic |
Copy Code
|
---|---|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click Dim dialog = New OpenFileDialog() dialog.Filter = "PDF files|*.pdf|HTML files|*.html;*.mhtml" If dialog.ShowDialog() = True Then Using fileStream = dialog.File.OpenRead() Try C1ReportViewer1.LoadDocument(fileStream) Catch ex As Exception MessageBox.Show("Failed to load document.") End Try End Using End If End Sub |
C# |
Copy Code
|
---|---|
private void Button1_Click(System.Object sender, System.Windows.RoutedEventArgs e) { dynamic dialog = new OpenFileDialog(); dialog.Filter = "PDF files|*.pdf|HTML files|*.html;*.mhtml"; if (dialog.ShowDialog() == true) { using (fileStream == dialog.File.OpenRead()) { try { C1ReportViewer1.LoadDocument(fileStream); } catch (Exception ex) { MessageBox.Show("Failed to load document."); } } } } |
This code initializes a dialog box to be opened when the button is clicked. In the dialog box users can select a file to open in the C1ReportViewer control. Notice how, in the code above, the LoadDocument method allows you to load PDF and HTML content.