tags:

views:

186

answers:

1

Is it possible to automate lotus notes to post a local file to a database? I have a daily task to post a logfile to a notes database. I can gather the logfile via script but don't know enough about notes scripting to figure this out.

I know thrre is a com interface as long as I have the client on the PC, but I can't figure out how to get a file uploaded to a dataase. I can use either vbscript or (preferred) powershell

+3  A: 

If you search around the net you'll find examples of using VBScript to manipulate Lotus Notes. Here's one example: http://haveworld.blogspot.com/2006/10/vbscript-and-lotus-notes.html

You'll need to know a little about Lotus Notes to make this work, though. Start small and see if you can even get the Notes Version to appear:

Set oNotesSession = CreateObject("Notes.Notessession") 'create notes session
Msgbox oNotesSession.NotesVersion

If that works, you know you're in good shape. If not, make sure you've installed Lotus Notes correctly and configured it on the client.

The code to post a local file to a database involves connecting to Notes, creating a new Notes Document, adding a file object into the body of the document, and then saving it. You can use any kind of Notes Database to do this, but I'd suggest creating a new one based on the Document Library template, and using that to store your files.

Here is some code that will create a new Notes document, set the subject field, attach a file, and then save the document. This assumes there's a local Notes database already available called "FileStorage.nsf"

strFileName = "C:\Windows\Media\tada.wav"
strSubject = "Your Subject Goes Here"

Set oNotesSession = CreateObject("Notes.Notessession") 'create notes session
Set oDb = oNotesSession.GetDatabase("", "FileStorage.nsf") 'open database on local named FileStorage.nsf
Set oDoc = oDb.CreateDocument

' Filling the fields
oDoc.Subject = strSubject
Set oBody = oDoc.CreateRichTextItem("Body")
oBody.EmbedObject 1454, "", strFileName   '1454 = Embedded Attachment type

oDoc.Save False, False
Ken Pespisa
thanks I'll try this as soon as I can. I have to use an existing notes database, is all I need the database name to use getdatabase?
Jim B
Yes. That first parameter is the server name, but if you're using a local database you can just leave that set to the empty string. If your database is within a folder, you'll need the path from the data directory, so use GetDatabase("", "myfolder\filestorage.nsf")
Ken Pespisa