Dokumente in SharePoint 2013 (ExtractFile)

  • Dim sDir As String
    Dim ses As NotesSession
    Dim work As NotesUIWorkspace
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument


    Sub Initialize


    Set ses = New NotesSession
    Set work = New NotesUIWorkspace
    Set db = ses.CurrentDatabase
    Set dc = db.UnprocessedDocuments
    Set doc = dc.GetFirstDocument
    Dim rtitem As NotesRichTextItem
    Dim RTNames List As String
    Dim DOCNames List As String
    Dim itemCount As Integer
    Dim sDefaultFolder As String
    Dim x As Integer
    Dim vtDir As Variant
    Dim iCount As Integer
    Dim j As Integer
    Dim lngExportedCount As Long
    Dim attachmentObject As Variant


    While Not (doc Is Nothing)


    iCount = 0
    itemCount = 0
    lngExportedCount = 0
    Erase RTNames
    Erase DocNames


    ForAll i In doc.Items


    If i.Type = RICHTEXT Then
    Set rtItem = doc.GetfirstItem(i.Name)
    If Not IsEmpty(rtItem.EmbeddedObjects) Then
    RTNames(itemCount) = CStr(i.Name)
    itemCount = itemCount +1
    End If
    End If


    End ForAll


    For j = 0 To itemCount-1
    Set rtItem = Nothing
    Set rtItem = doc.GetfirstItem(RTNames(j))
    ForAll Obj In rtItem.EmbeddedObjects
    If ( Obj.Type = EMBED_ATTACHMENT ) Then
    Call ExportAttachment(Obj)
    Call doc.Save( False, True )


    End If
    End ForAll
    Next


    ForAll i In doc.Items


    If i.Type = ATTACHMENT Then


    DOCNames(lngExportedCount) = i.Values(0)
    lngExportedCount = lngExportedCount + 1


    End If


    End ForAll


    For j% = 0 To lngExportedCount-1
    Set attachmentObject = Nothing
    Set attachmentObject = doc.GetAttachment(DOCNames(j%))
    Call ExportAttachment(attachmentObject)
    Call doc.Save( False, True )


    Next


    Set doc = dc.GetNextDocument(doc)
    Wend


    MsgBox "Export Complete.", 16, "Finished"


    End Sub



    Sub ExportAttachment(o As Variant)


    Dim ses As New NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim varDate As Variant
    Dim strYear As String
    Dim strMonth As String
    Dim strFolderName As String


    Set db = ses.CurrentDatabase
    Set dc = db.AllDocuments
    Set doc = dc.GetFirstDocument()
    While Not doc Is Nothing
    varDate = doc.GetItemValue( "Date" )(0)
    strYear = CStr( Year( varDate ) )
    strMonth = CStr( Month( varDate ) )
    strFolderName = strYear & "\" & strMonth
    Call doc.PutInFolder( strFolderName )
    Set doc = dc.GetNextDocument( doc )
    Wend


    Print "Exporting " & strFolderName


    Call o.ExtractFile( strFolderName )


    End Sub



    Hallo Leute,


    ich bekomme eine Fehlermeldung Type Misstach.


    Ich habe eine Datenbank mit ca. 5000 Dokumenten. Ein Dokument beinhaltet Information wie z.B. Name, Datum, Betrag, Kommentar und ein Body-Feld (meistens .pdf).


    Ich möchte ich die Anhänge.pdf (Body-Feld) in Windows-Explorer exportieren. Das klappt auch. Nun möchte ich aber, dass es
    bisschen sortierter wird, Ordner erstellen lassen mit den Datumswerten und dann in den Ordner die passenden Anhänge.


    Vielen Dank im Voraus


    MFG
    Max

  • Moin
    Der Fehler ist irgendwie öd.
    In welcher Zeile bekommst Du den Fehler ? Wo ist dein Error handling ?


    Schau mal in der Designerhilfe unter "on error goto " bzw. Erl bzw. error$ bzw. err

  • Hat das doc auch das Itemn "Date" und ist das auch nicht leer, bzw. von welchem Typ ist das Item?

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

  • Du holst dir mit GetItemValue(...)(0) einen String, davon die Jahresinformation und die resultierende Zahl wandelst du in einen String um ... das muss ich nicht verstehen, oder? Warum nicht gleich den String entsprechend auseinanderpflücken?


    Aber genau das ist vermutlich auch das Problem: GetItemValue(..)(Index) gibt einen String zurück, Year() frisst aber nur Zeitwerte.


    Wenn du es unbedingt auf diese Weise machen willst, nimm Cstr(Year(DateValue(doc.GetItemValue("Date")(0)))) ... das ist zwar noch furchtbarer zu lesen, sollte aber tun.

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

  • Sub ExportAttachment(o As Variant)


    Dim sAnhangName As String
    Dim sNum As String
    Dim sTemp As String
    Dim ses As New NotesSession
    Dim db As NotesDatabase
    Dim dc As NotesDocumentCollection
    Dim doc As NotesDocument
    Dim varDatum As Variant
    Dim strJahr As String
    Dim strMonat As String
    Dim strOrdnerName As String

    Set db = ses.CurrentDatabase
    Set dc = db.AllDocuments
    Set doc = dc.GetFirstDocument()
    While Not doc Is Nothing
    varDatum = doc.GetItemValue( "Date" )(0)
    strJahr = CStr( Year( varDatum ) )
    strMonat = CStr( Month( varDatum ) )
    strOrdnerName = strJahr & "\" & strMonat
    MkDir("C:\Projekte\Dokumente")
    Set doc = dc.GetNextDocument( doc )
    Wend


    sAnhangName = sDir & "\" & o.Source
    While Not (Dir$(sAnhangName, 0) = "")
    sNum = Right(StrLeftBack(sAnhangName, "."), 2)
    If IsNumeric(sNum) Then
    sTemp = StrLeftBack(sAnhangName, ".")
    sTemp = Left(sTemp, Len(sTemp) - 2)
    sAnhangName = sTemp & Format$(CInt(sNum) + 1, "##00") & _
    "." & StrRightBack(sAnhangName, ".")
    Else
    sAnhangName = StrLeftBack(sAnhangName, ".") & _
    "01." & StrRightBack(sAnhangName, ".")
    End If
    Wend


    Print "Exporting " & sAnhangName
    'Save the file
    Call o.ExtractFile( sAnhangName )


    End Sub



    Hallo Leute,


    bekomme nun die Fehlermeldung Path/file Access error..


    Ich hoffe Ihr könnt mir weiterhelfen. Bin auf den Fehler einfach nicht draufgekommen.


    Vielen Dank

  • An welcher Stelle? Beim MkDir oder beim ExtractFile?
    AFAIK braucht der Agent für FS-Operationen uneingeschränkte Rechte, hast du an der Stelle nachgeschaut?

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl

  • Was willst du prüfen?
    Du hast vorne dran ein MkDir, das einen Fehler wirft, wenn das Verzeichnis nicht erstellt werden kann. Ich nehme doch an, du hast selbstverständlich ein brauchbares Error Handling und hast das nur der Übersichtlichkeit halber hier aus den geposteten Snippets rausgeworfen.

    Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming "Wow, what a ride!!! :evil:
    Beschleunigung ist, wenn die Tränen der Ergriffenheit waagrecht zum Ohr hin abfliessen - Walter Röhrl