Display PDF in New Browser Tab or HTML Viewer

I’ve searched the forum but I cannot seem to find a solution that works for me so let me explain what I want to do or at least what I’ve tried. I have a Web app that on the main web page it reads from a database to fill a Listbox with data, (job details). I can right click on a job row and open a dialog box with a listbox of data that is a list of files related to the job record in the listbox on the main web page. I can right click on a file and I want it to either open it in a new browser window or alternatively in an HTML viewer. All the files related to the job are PDF files. they are all SMB UNC paths. The web app runs on windows The pats resemble this format: \\\\servername\\sharename\\subfolder1\\subfolder2\\subfolder3\\subfolder4\\filename.pdf

My first attempt was to just open the file URL in a new Browser tab:

Dim s As String ="file:" + ReplaceAll(ListBox_InputFiles.Cell(InputRowSelected,2),"\","/") Me.ShowURL(s,True)

This results in a new tab opening but the URL showing is about:blank
the URL when sent to a MsgBox is file://servername/sharename/subfolder1/subfolder2/subfolder3/subfolder4/filename.pdf which opens just fine when pasted into the blank tab so the URL is valid it’s just not getting passed.

My next attempt was to try a different method:

Dim PDFWebFile As New WebFile Dim s As String = ListBox_InputFiles.Cell(InputRowSelected,2) Dim f As FolderItem f = GetFolderItem(s) PDFWebFile = WebFile.Open(f) PDFWebFile.MIMEType = "application/pdf" Me.ShowURL(PDFWebFile.URL,True)

This results in a new tab opening with the following message:

404: File Not Found The requested URL "/6C352733B7910601B738D278B0CFB376F023F67A/files/8853-7187-9855-9137-7274/filename.pdf" could not be found. Please check your request and try again.

This code was borrowed from another thread and is almost identical except I needed to use GetFolderItem since it wasn’t in a local SpecialFolder. I have no idea why it isn’t working.

My last attempt was to try opening in a new dialog with an HTML viewer but little differnce from the new tab attempt:

Session.PDFViewer = New HTMLviewerDialog Session.PDFViewer.Show Dim PDFWebFile As New WebFile Dim s As String = ListBox_InputFiles.Cell(InputRowSelected,2) Dim f As FolderItem f = GetFolderItem(s) PDFWebFile = WebFile.Open(f) PDFWebFile.MIMEType = "application/pdf" Session.PDFViewer.HTMLViewer_PDF.URL = PDFWebFile.URL

Of course the error method is virtually identical to ther one in the new tab.

404: File Not Found The requested URL "/66F63F6D8F17B3021C124FE6BEEE531194F415CB/files/2062-4745-0465-6413-3567/filename.pdf" could not be found. Please check your request and try again.

I know I’m probably missing something simple but I’m not seeing it. Can anyone point me to a direction that will work? I just need the users to preview the PDF file. The internal users this app is intended for will always have acrobat loaded so PDFs can open in their browser and they will always be using a fairly recent version of Chrome since both apps are set by Group Policy. They would have to purposely open a different browser other than the default to not open the app in Chrome.

You should make PDFWebFile a property of your webpage, or of session, so it does not disappear out of scope.

Doh! Of course. I missed that simple little thing. Thanks Michel!