Copy Attachments to Folder

140 pts.
Tags:
Lotus Domino
Lotus Notes 6.x
LotusScript
ODBC
SQL
Anyone have a lotusscript to copy attachments to a folder? Also need to extract to excel a view but right now i think i can handle that with NotesSQL ODBC. The attachments part is buging me the most. This is not a mail system.... We have a database setup for document approvals. Lotus Domino 6.5

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is a simple code from Notes Help ..

This script detaches and removes all the file attachments in a document’s Body item that are larger than 100,000 bytes. The first file attachment that’s found gets detached to c:\reports\newfile1, the second attachment that’s found gets detached to c:\reports\newfile2, and so on.

Dim doc As NotesDocument
Dim rtitem As Variant
Dim fileCount As Integer
Const MAX = 100000
fileCount = 0
‘…set value of doc…
Set rtitem = doc.GetFirstItem( “Body” )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) _
And ( o.FileSize > MAX ) Then
fileCount = fileCount + 1
Call o.ExtractFile _
( “c:\reports\newfile” & Cstr(fileCount) )
Call o.Remove
Call doc.Save( True, True )
End If
End Forall
End If

My new Version…. small issue with multiple attachments? any help?
by Maramor
<pre>
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim outFileName As String
Dim outFile As Integer
Dim pathName As String
Dim fileName As String
Dim dirName As String
Dim fName As String

pathName = “C:\samples”

outFileName= “C:\samples\OriginalNameLog.txt”
outFile = Freefile()
Open outFileName For Output As outFile

outFileName1= “C:\samples\ErrorBadChr.txt”
outFile1 = Freefile()
Open outFileName1 For Output As outFile1

Set db = session.CurrentDatabase
Set collection = db.AllDocuments
Set doc = collection.GetFirstDocument()
While Not(doc Is Nothing)
If doc.HasEmbedded Then
dirName = doc.NoteID
pathName = pathName & “” & dirName
Mkdir pathName
Forall it In Doc.Items
If it.name = “$FILE” Then
fileName = it.values(0)
Set f= Doc.GetAttachment( fileName)
fName = StrFixFilename(fileName,””)
Call f.ExtractFile(pathName & “” & fName)
If fileName = fname Then
Print #outFile, dirName & “” & fileName
Else
Print #outFile, dirName & “” & fileName & ” Changed To ” & dirName & “” & fName
Print #outFile1, dirName & “” & fileName & ” Changed To ” & dirName & “” & fName
End If
If Not it.values(1) = Null Then
fileName1 = it.values(1)
Set f1= Doc.GetAttachment( fileName1)
fName1 = StrFixFilename(fileName1,””)
Call f1.ExtractFile(pathName & “” & fName1)
If fileName1 = fname1 Then
Print #outFile, dirName & “” & fileName1
Else
Print #outFile, dirName & “” & fileName1 & ” Changed To ” & dirName & “” & fName1
Print #outFile1, dirName & “” & fileName1 & ” Changed To ” & dirName & “” & fName1
End If
End If
End If
End Forall
End If
Set doc = collection.GetNextDocument(doc)
Wend
Close outFile
Close outFile1
End Sub
Public Function StrFixFilename(Byval fileName As String, Byval replaceChar As String)

‘/**
‘ * Replaces invalid characters in a filename with a specific character.
‘ * @param filePath The file name to fix.
‘ * @param replaceChar The character to use for replacing invalid characters.
‘ * @return A valid filename.
‘ */

Dim badChars As Variant
badChars = Split({?})
Forall badChar In badChars
NewfileName = Replace(fileName, badChar, replaceChar)
End Forall
StrFixFilename = NewfileName
End Function
</pre>

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Maramor
    ooo, to reduce confusion.... I mean C:\ or Network Share.
    140 pointsBadges:
    report
  • Maramor
    I like what you got... as I play with yours making my changes.................... Would the below download/copy the attachments for Selected Lotus Documents? I get variable not set error. I am working with a test database and it is possible no attchments exist. I am new to Lotus LoL. In the production env, I need to extract the attached pdf files but not harm the current lotus items. Sub Initialize Dim doc As NotesDocument Dim rtitem As Variant '...set value of doc... Set rtitem = doc.GetFirstItem( "Body" ) If ( rtitem.Type = RICHTEXT ) Then Forall o In rtitem.EmbeddedObjects If ( o.Type = EMBED_ATTACHMENT ) Then Call o.ExtractFile( "c:\samples\" & o.Source ) Call doc.Save( False, True ) End If End Forall End If End Sub
    140 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following