How can I Detach a File Resource using LotusScript

I have a File Resource which is an MS Word Template (.dot). I want to use this file from a LotusScript agent which was kicked off by a web user.

How do I get and detach this file?

Thank you.

Jeff

PS: I managed to get the Note with the following code, but I can’t get the file or detach it.

Sub Initialize

Dim db As NotesDatabase

Dim nc As NotesNoteCollection

Dim s As New NotesSession

Dim nid As String

Dim i As Integer

Dim doc As NotesDocument



Set db = s.CurrentDatabase

Set nc = db.CreateNoteCollection(True)

Call nc.BuildCollection



nid = nc.GetFirstNoteId

For i = 1 To nc.Count

	Set doc = db.GetDocumentByID(nid)

	If doc.HasItem("$Title") Then

		If doc.GetFirstItem("$Title").Values(0) = "Survey.dot" Then

			Print doc.NoteID, doc.UniversalID, doc.GetFirstItem("$Title").Values(0), doc.GetFirstItem("$FileNames").Values(0)

		End If

	End If

	nid = nc.GetNextNoteId(nid)

Next i

End Sub

Subject: How can I Detach a File Resource using LotusScript

Look into NotesEmbeddedObject in Notes help.

Subject: How can I Detach a File Resource using LotusScript

File resources are not stored as attachments (although I am not sure why not). They are stored as composite data records, so that the $FileData items comprise a SIG_CD_FILEHEADER record followed by a series of SIG_CD_FILESEGMENT records. We create and manipulate them a bit with our Midas Rich Text LSX, so it is possible you could get the file using that, but you can’t just attach or detatch the files.

Subject: Suggestion

Instead of storing the file as a File Resource, consider attaching it to a Profile document. It will be easy to detach from that.

Subject: *This is a good suggestion

Subject: Not such a good suggestion

Unfortunately attachments and embedded files in rt fields inside profile documents tend to corrupt from time to time.File resources are much more stable!

Subject: How can I Detach a File Resource using LotusScript

What do you want to do with the file once you detach it? If you just want to launch it for the user, you could use a print statement in LS to open the resource (Print “[servername/db.nsf/Survey.dot]”. If you want to write to the document, I would suggest attaching the file to a document (profile documents can cause rather vicious fits) and pulling the file from there. I did this recently for an application and it works great. It will make it easier down the road (for both user, if given the power, and any future developers) to change if the Word template needs updating.