Manage Learn to apply best practices and optimize your operations.

Class Attachment


C L A S S "ArraySets"
Class ArraySets
Public Value() As String
Public TotalElements As Integer

Sub Init
TotalElements = 0
Redim Value(1 To 1) As String
End Sub

Sub AddElement(NewValue As String)
TotalElements = TotalElements + 1
Redim Preserve Value(1 To TotalElements) As String
Value(TotalElements) = NewValue
End Sub

Function Search(SearchFor As String) As Integer
Dim CurrentLabelEntry As Integer
CurrentLabelEntry = 1
Forall c In Value
If Ucase(c) = Ucase(SearchFor) Then Exit Forall
CurrentLabelEntry = CurrentLabelEntry + 1
End Forall
Search = CurrentLabelEntry
End Function
End Class

C L A S S "Attachment"
Class Attachment

Declare Public Function DetachAll (path As String, ItemtoAttachFrom As String, overwrite As Integer) As Variant
Declare Public Function IsPathAvailable (path As String) As Variant
Declare Public Function Count (InItem As String) As Integer
Declare Public Function GetNthAttachment (InItem As String, Position As Integer) As Variant
Declare Public Function GetAttachmentByName (InItem As String, AttName As String) As Variant
Declare Public Function DetachByName (InItem As String, AttName As String, path As String, overwrite As Integer) As Variant
Declare Private Function IsDriveAvailable (drivNam$) As Variant

Public doc As NotesDocument

Sub New
path = ""
End Sub

Public Function DetachByName (InItem As String, AttName As String, path As String, overwrite As Integer) As Variant
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Dim rtitem As Variant
Set rtitem = doc.GetFirstItem( InItem )
If IsDriveAvailable(Left(path,3)) Then
Chdrive Left(path,3)
IsPathAvailable(path)
Chdir path
i% = 1
j% = GetAttachmentByName( InItem, AttName)

If j% > count(InItem) Then
DetachByName = False
Exit Function
Else
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If j% = i% Then
Call o.ExtractFile(o.Name)
End If
i% = i% + 1
End Forall
End If
End If
DetachByName = True
Else
DetachByName = False
End If
End Function

Public Function GetAttachmentByName (InItem As String, AttName As String) As Variant
Dim Array As New ArraySets
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As Variant
Dim Whereis As Integer
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set rtitem = doc.GetFirstItem( InItem )
notesEmbeddedObject = rtitem.EmbeddedObjects
Call Array.Init

If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
Array.AddElement(o.name)
End Forall
Else
End If
WhereIs = Array.Search(AttName)
GetAttachmentByName= WhereIs
End Function

Public Function GetNthAttachment (InItem As String, Position As Integer) As Variant
If count(InItem) < Position Then
GetNthAttachment = True
Exit Function
Else
Dim Array As New ArraySets
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As Variant
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set rtitem = doc.GetFirstItem( InItem )
notesEmbeddedObject = rtitem.EmbeddedObjects
Call Array.Init
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
Array.AddElement(o.name)
End Forall
Else
End If
GetNthAttachment = Array.Value(Position)
End If
End Function

Public Function Count (InItem As String)As Integer
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As Variant
Dim i As Integer
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set rtitem = doc.GetFirstItem( InItem )
notesEmbeddedObject = rtitem.EmbeddedObjects
i = 0
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
i = i +1
End Forall
Else
End If
count = i
End Function

Function DetachAll (path As String, ItemtoAttachFrom As String,overwrite As Integer) As Variant
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim rtitem As Variant

DetachAll = True

If IsDriveAvailable(Left(path,3)) Then
Chdrive Left(path,3)
IsPathAvailable(path)
Chdir path
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set rtitem = doc.GetFirstItem( ItemtoAttachFrom )
notesEmbeddedObject = rtitem.EmbeddedObjects
If overwrite = 1 Then
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
Call o.ExtractFile(o.Name)
End Forall
Chdrive Left(path,3)
Chdir Left(path,3)
End If
Else
End If

Else
DetachAll = False
End If
End Function

Private Function IsDriveAvailable(drivNam$) As Variant
'// Test, ob das Laufwerk vorhanden ist
On Error Goto Errors
IsDriveAvailable = False
If Dir$(drivNam, 8) <> "" Then
IsDriveAvailable = True
End If
TheEnd:
Exit Function
Errors:
Resume TheEnd
End Function

Public Function IsPathAvailable(path As String) As Variant
'// Test, ob das Pfad vorhanden ist; wenn nicht, wird Pfad angelegt
Dim session As New NotesSession
Dim MyPath$, tmpPath$
Dim result%, pos%

On Error Resume Next
If IsDriveAvailable(Left(path,3)) Then
Chdrive Left( path, 1 )
Chdir path
result = False
pos = 1
If Curdir + "" <> path Then
If Right( path, 1 ) <> "" Then path = path + ""
If path = "" Then Goto Exit_CheckDir
Chdrive Left( path, 1 )
Do While pos <> 0
pos = Instr( pos, path, "" )
If pos > 0 Then
tmpPath = Left( path, pos-1 )
Mkdir tmpPath
Chdir tmpPath
pos = pos + 1
End If
Loop
If Curdir + "" = path Then
result = True
End If
Else
result = True
End If
Else
End If
Exit_checkDir:
IsPathAvailable = result
Exit Function
End Function
End Class

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close