I wanted to launch a excel (xls) file which was stored in a Profile document, from a Notes Client (tested in r8.5 but I see no reason this will not work in versions going back to r5)
(Making it available to all users of a certain type of document with making hundreds of replicate copies, and all a central db administrator user able to roll out a new file with out changing those other documents)
It is not very obvious how to do this, hence this posting
My first Draft was this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Dim workspace AsNewNotesUIWorkspace Dim session AsNewNotesSession Dim db AsNotesDatabase Dim Pdoc AsNotesDocument Dim attachments AsVariant Dim attachment AsNotesEmbeddedObject
Set db = session.CurrentDatabase Set Pdoc = db.GetProfileDocument("ApplicationProfileDocument")' get the profile document
attachments = Evaluate("@AttachmentNames", Pdoc) Set attachment = Pdoc.GetAttachment(attachments(0))'use a evalutate to get the first "(0)" file attachment
Call attachment.ExtractFile("c:" & attachment.Name)' write it out to the hard drive Set e = CreateObject("Excel.Application")' open excel Set eWB = e.Workbooks.Open("c:" & attachment.Name)' open the file in excel
eWB.Visible = True'make the opened excel file visible
There was a problem the that code in that I could be sure that there weren’t other file attachments and the first one was going to be the one I wanted.
I’ve tried to correct that problem here :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Dim workspace AsNewNotesUIWorkspace Dim session AsNewNotesSession Dim db AsNotesDatabase Dim Pdoc AsNotesDocument Set db = session.CurrentDatabase Set Pdoc = db.GetProfileDocument("ApplicationProfileDocument")
Set rtitem = Pdoc.GetFirstItem("RichTextFilewithFileAttacment")'get the field I know the file is in. If( rtitem.Type = RICHTEXT )Then Forall o In rtitem.EmbeddedObjects If( o.Type = EMBED_ATTACHMENT )Then Call o.ExtractFile("c:" & o.Name)' write it out to the c: hard drive Set e = CreateObject("Excel.Application")' open excel Set oWB = e.Workbooks.Open("c:" & o.Name)' open the file in excel
oWB.Visible = True'make the opened excel file visible EndIf EndForall EndIf
This will actually launch all the files that are attached in the rich text (or rich text light) field, which I could limit by doing some validation work on the Profile form to ensure only 1 file is attached.
2 (possibly) big assumptions :
This is a windows machine with a c: drive and enough free space. this is testable but I’m too lazy/busy/silly (please only pick one).
The file to be launched is an Excel. This could be allow for be testing the file name extension and doing the appropriate thing. (and that assumes the MS Excel is the application for that file extension and the Open Office, or something similar).
update: Collin and Sean both make go points and reminded me of another thing : Execution Control List’s (ECL) which control access on the Notes Client. You may need to get the notes database signed with a ID that has right to write to the file system in your organization, or your end users will be prompted with a “Execution Security Alert” with will ask them to either stop the action, execute once or trust the id used.