ComponentOne PDF for WPF and Silverlight
Opening Potentially Protected Files
PDF for WPF and Silverlight Overview > Task-Based Help > Opening Potentially Protected Files

When giving the end-user the ability to open a PDF file, sometimes you can’t predict whether or not the file will be password protected or not. The following sample method demonstrates how to perform this check and open the document accordingly:

Visual Basic
Copy Code
Private Sub _btnOpen_Click(sender As Object, e As RoutedEventArgs)

        Dim dlg = New OpenFileDialog()

        dlg.Filter = "Pdf files (*.pdf)|*.pdf"

        If dlg.ShowDialog().Value Then

            Dim ms = New System.IO.MemoryStream()

            Using stream = dlg.File.OpenRead()
               
              stream.CopyTo(ms)

            End Using

            LoadProtectedDocument(ms, Nothing)
       
            End If

    End Sub
C#
Copy Code
void _btnOpen_Click(object sender, RoutedEventArgs e)

        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "Pdf files (*.pdf)|*.pdf";

            if (dlg.ShowDialog().Value)

            {
                var ms = new System.IO.MemoryStream();

                using (var stream = dlg.File.OpenRead())
                {

                    stream.CopyTo(ms);
                }

                LoadProtectedDocument(ms, null);

            }
        }

When giving the end-user the ability to open a PDF file, sometimes you can’t predict whether or not the file will be password protected or not. The following sample method demonstrates how to perform this check and open the document accordingly: