Disclaimer and License

Opinions expressed here by Tim Tripcony are his own and not representative of his employer.

Creative Commons License
Tip of the Iceberg is licensed under a Creative Commons Attribution 3.0 Unported License.
Based on a work at timtripcony.com.

Unless otherwise explicitly specified, all code samples and downloads are copyright Tim Tripcony and licensed under Apache License 2.0.

Search

What the Quote?

"It's an enzyme that keeps you from farting when you eat chili."

Devin Olson

"If I were wearing cargo pants, I'd really be disoriented."

Tim Tripcony

"In order to understand recursion, one must first understand recursion."

Author Unknown

« Top 5 | Main| Nathan ripples the walls »

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.

Comments

Gravatar Image1 - Hi Tim,

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

Gravatar Image2 - Indeed... if the SizeToWindow property is set to True, it ignores other properties like Top, Left, Width and Height and just overlaps the entire form content.

Gravatar Image3 - Actually I found it after reading this article - { Link }

Seems you have to play with the properties panel.

Gravatar Image4 - This is great. I looked at the perweb.nsf when I got frustrated trying to get active x controls working in the client. I simply didn't know enough to know how it all worked together. This is excellent!

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.

Gravatar Image5 - Thanks, Wayne... I'll check that out. Given a choice, I'd prefer Mozilla to I.E. anyway.

Gravatar Image6 - Nifty technique, I can see using this to view images in an image retrieval app I wrote. That would eliminate the need to install software, too, so I'll have to give it a whirl.

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.

Gravatar Image7 - sweeeeeeet

Gravatar Image8 - @8 - Not yet... so far I've only used it in the embedded frame context, so the control is set to fill its frame, and the frameset determines the frame's size.

Gravatar Image9 - Nice work!

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.

Gravatar Image10 - Hi

I was trying to check this out and then reuse the technique to get the browser to inline open an XL spreadsheet. But even when I deploy this app locally and try to open a ebook, I get the prompt to Open/Save/Edit attachment and then the word doc opens in its own window. This happens in Windows Vista, Lotus Notes 8.5. I am thinking this is because of some file association but I don't find a way to change the file association option (which I know in XP). Any help appreciated

Gravatar Image11 - Used this approach for an app to provide flash-based training files to select users. Everything worked fine for months. Files would be extracted from Notes document to user's local Eviron("TEMP") folder and then launched from there. Now have a user with a single quote in their name (e.g. james.o'brien) so the temp folder is retrieved as "C:\Documents and Settings\james.o'brien\My documents". For this user the files get extracted fine but when launched the user only gets a blank screen because the file can't be found. Looking at the code that is generated in the browser I can see that the file reference is truncated at the single quote position (e.g. "{ Link } Any thoughts on how to resolve thiswould be greatly appreciated.

Gravatar Image12 - @John - I'm guessing the apostrophe needs to be escaped. The scripting language used by Flash is ActionScript, which is nearly identical to JavaScript, so it would treat an apostrophe as the start of a String literal unless it were preceded by a backslash.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)