SnTT: using the WebBrowser control to view attachments inline
Category show-n-tell thursday
If you've ever set a form to launch the first attachment upon document open, but wished (or received requests from users) that it wouldn't open a separate application window, there's another option. Nathan and I were experimenting with this, and here's what we came up with:
In the standard perweb.nsf there is a form called "WebBrowserForm", which contains an embedded control of class "Shell.Explorer.1" with its name set simply to "Browser". When you open a URL within Notes, you're essentially creating a new document using this form that, during the PostOpen, gets a handle on the browser control ( Set browserobject=uidoc.GetObject("Browser") ), and tells it to navigate to the web page ( browserobject.navigate doc.url(0) ). Although I've been unable to find a way to create this control using the Create > Object dialog, you can copy it from the original form into your own applications and take advantage of its ease of use.
The sample database is just a basic e-book reader. Its interface is a horizontal preview - a two frame collapsible frameset, with a table of contents view in the left frame and an empty preview frame on the right side. So, just like the standard mail Inbox, when a document is selected, if the preview frame is expanded, the document is loaded in preview mode. But here's where it gets a wee bit fancy.
The form's QueryOpen extracts whatever file is attached to the user's temp directory. The PostOpen gets a handle on the WebBrowser control, but instead of telling it to navigate to a URL, it navigates to the extracted file's path, which - if the filetype is one that I.E. can load inline - launches the file... inside Notes. So if the file is a PDF, for example, Adobe launches inside the preview pane instead of opening a separate application window just for itself. And, since the browser control is set to fill the window, the external application automatically scales to the preview pane. Imagine Nathan's Sesame Street demo, but a full-fledged Adobe Reader window off to the right instead of Big Bird.
This works not only for PDF's, but for text files, Office (if installed), and of course, good old HTML files. Even Quicktime movies and MP3's... AVI's and MPG's launch Media Player in a separate window. Basically, any file that, if clicked in a web page, would be loaded within the browser instead of triggering a download prompt or launching a separate app can be "previewed" in this manner. It's basically the standard attachment viewer on steroids. NOTE: viewer, not editor. If you open a Word doc, it'll be fully editable (assuming no constraints on the original file), but any changes you save are written back to the extracted copy in the temp folder, not to the copy attached to the Notes document. You'll probably want to make this abundantly clear to your users if you implement this approach in your own applications, particularly if they're now addicted to the standard in-place attachment editing capability.
If you've ever set a form to launch the first attachment upon document open, but wished (or received requests from users) that it wouldn't open a separate application window, there's another option. Nathan and I were experimenting with this, and here's what we came up with:
In the standard perweb.nsf there is a form called "WebBrowserForm", which contains an embedded control of class "Shell.Explorer.1" with its name set simply to "Browser". When you open a URL within Notes, you're essentially creating a new document using this form that, during the PostOpen, gets a handle on the browser control ( Set browserobject=uidoc.GetObject("Browser") ), and tells it to navigate to the web page ( browserobject.navigate doc.url(0) ). Although I've been unable to find a way to create this control using the Create > Object dialog, you can copy it from the original form into your own applications and take advantage of its ease of use.
The sample database is just a basic e-book reader. Its interface is a horizontal preview - a two frame collapsible frameset, with a table of contents view in the left frame and an empty preview frame on the right side. So, just like the standard mail Inbox, when a document is selected, if the preview frame is expanded, the document is loaded in preview mode. But here's where it gets a wee bit fancy.
The form's QueryOpen extracts whatever file is attached to the user's temp directory. The PostOpen gets a handle on the WebBrowser control, but instead of telling it to navigate to a URL, it navigates to the extracted file's path, which - if the filetype is one that I.E. can load inline - launches the file... inside Notes. So if the file is a PDF, for example, Adobe launches inside the preview pane instead of opening a separate application window just for itself. And, since the browser control is set to fill the window, the external application automatically scales to the preview pane. Imagine Nathan's Sesame Street demo, but a full-fledged Adobe Reader window off to the right instead of Big Bird.
This works not only for PDF's, but for text files, Office (if installed), and of course, good old HTML files. Even Quicktime movies and MP3's... AVI's and MPG's launch Media Player in a separate window. Basically, any file that, if clicked in a web page, would be loaded within the browser instead of triggering a download prompt or launching a separate app can be "previewed" in this manner. It's basically the standard attachment viewer on steroids. NOTE: viewer, not editor. If you open a Word doc, it'll be fully editable (assuming no constraints on the original file), but any changes you save are written back to the extracted copy in the temp folder, not to the copy attached to the Notes document. You'll probably want to make this abundantly clear to your users if you implement this approach in your own applications, particularly if they're now addicted to the standard in-place attachment editing capability.








Comments
Posted by Scott At 11:16:34 On 07/19/2007 | - Website - |
To add a browser control to your own form:
Create > Object
Change the top section to Control
Select Microsoft Web Browser Control from the list
On my XP PC it has a class of Shell.Explorer.2, but the Registry shows Shell.Explorer.1 mapped to the same DLL.
Posted by Charles Robinson At 13:31:52 On 07/26/2007 | - Website - |
FYI there is a Mozilla activex component "{ Link }
that is supposed to be compatable with the ie component.
Perhaps you could get results with it.
Posted by Wayne Sobers At 19:10:00 On 08/09/2007 | - Website - |
Posted by Tim Tripcony At 19:44:04 On 08/09/2007 | - Website - |
Great tip, much appreciated. Oddly I now seem to have an extra class appear under my Domino Objects - Webbrowser_v1 - not sure if it was there before
Have you managed to get the browser to not display full screen? Cant seem to get this to work - bascially want some information on the document to be visible and the browser object below it.
Any ideas?
Cheers
Mark
Posted by Mark Barton At 10:55:12 On 08/13/2007 | - Website - |
Seems you have to play with the properties panel.
Posted by Mark Barton At 11:12:38 On 08/13/2007 | - Website - |
Posted by Tim Tripcony At 14:04:07 On 08/13/2007 | - Website - |
Did you find any weaknesses with the WebBrowser control object? E.g. Ole Automation Errors/etc..
When I put the control inside a table, I got "Ole Automation Error" when trying to resize it PostOpen, which I can kind of understand.
Posted by Tommy Valand At 11:36:53 On 09/06/2007 | - Website - |
Posted by Tim Tripcony At 13:53:41 On 09/06/2007 | - Website - |