Adding a PDF from a File System
If you prefer not to add a PDF via a URL, you can add one in from your file system.
Add a PdfViewer Screen
1. In the Designer, click the Screen button or right-click the Screens folder in the Solution Explorer and choose Add Screen. The Add New Screen window opens.
2. Select ComponentOne PdfViewer Screen and click OK.
Add a Method
1. Choose the screen in the Solution Explorer.
2. Right-click on the Screen Command Bar and choose Add Button.
3. In the Add Button dialog box, name your New Method “OpenFile”.
4. Click OK. In the Properties, click on Choose Image.
5. Choose any image.
6. In the Designer, double-click on OpenFile in the list under Screen Command Bar. In the window, paste in the following code:
Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
{
// request file name
System.Windows.Controls.OpenFileDialog ofd = new System.Windows.Controls.OpenFileDialog();
ofd.Filter = "Pdf files (*.pdf)|*.pdf";
if (ofd.ShowDialog() == true)
{
ViewerDataLocation = ofd.File.FullName;
}
}
);
7. Run the project.
Choose a PDF
Now you can choose a PDF using the Open File button.
The PDF will now appear in the PDFViewer.