2013-09-24 101 views
0

我試圖從Lotus Notes數據庫(使用Designer 7.0)導出所有文檔及其附件。我可以獲取文檔數據並可以獲得附件,但前提是需要對名稱進行硬編碼。在LotusScript中,我發現以編程方式獲取文件名的兩種方法不起作用,如下面兩個代碼塊所示。在第一個中,doc.GetFirstItem(「Body」)返回Nothing,第二個,在Forall行上執行時會出現類型不匹配。 如何提取附件的任何幫助將不勝感激!我不確定附件是否以「附件」或OLE存儲,但我懷疑是附件,因爲它們主要是PDF。如何檢索Lotus Notes附件?

Sub Click(Source As Button) 
Dim session As New NotesSession 
Dim db As NotesDatabase 
Dim query As String 
Dim collection As NotesDocumentCollection 
Dim doc As NotesDocument 
Dim fileCount As Integer 
Dim attachment As NotesEmbeddedObject 
Dim fileName As String 

Set db = session.CurrentDatabase 
' get a document that has an attachment 
Set collection = db.FTSearch("06/25/2013", 10) 

fileNum% = Freefile() 
fileName$ = "c:\kcw\lotusexport.txt" 
Open fileName$ For Output As fileNum% 
Write #fileNum%, "docs found", collection.Count 

Set doc = collection.GetFirstDocument 
' write out document properties 
Forall x In doc.Items 
    Write #fileNum%, x.Name, " = ", x.Text 
End Forall 
'extract document (using hardcoded name) 
Set attachment = doc.GetAttachment("OCSE-FRONT_SCANTODESKTOP_06262013-104822.pdf") 
Call attachment.ExtractFile _ 
("c:\kcw\attachment") 

'Try to get attachment through "Body", but rtitem is Nothing 
Set rtitem = doc.GetFirstItem("Body") 
Write #fileNum%, "rtitem is Nothing", rtitem Is Nothing 
fileCount = 0 
If Not rtitem Is Nothing Then 
    If (rtitem.Type = RICHTEXT) Then 
     Write #fileNum%, "rtitem is RICHTEXT" 
     Forall o In rtitem.EmbeddedObjects 
      Write #fileNum%, "has Embedded Objects" 
      fileCount = fileCount + 1 
      Write #fileNum%,"rtitem num", fileCount 
      Call o.ExtractFile _ 
      ("c:\kcw\newfile" & Cstr(fileCount)) 
     End Forall 
    End If 
End If 

'Fails with "Type mismatch" at Forall loop 
If doc.HasEmbedded Then 
    Write #fileNum%, "doc has embedded"  
    Forall objects In doc.EmbeddedObjects 
     Write #fileNum%, "in for loop" 
     Write #fileNum%, "filename= ", object.Source 
    End Forall 
End If 

Close fileNum% 
End Sub 
+0

Dim session ..etc。是什麼意思? – zanbri

+0

Body字段是否存在於每個文檔中?非常奇怪,它什麼都沒有返回。 –

+0

你絕對應該看看LotusScript中的錯誤處理技術。在循環中處理文檔可能會有一些問題 - 隨時可以處理。剛剛從所述頭部的頂部:不同形式(無體字段),損壞的DOC(.isValid),無效的文件名等(內部附件的名稱可以從一個客戶端中所示不同)。 –

回答

3

,這將使你的所有附件的清單文件

objects = Evaluate("@AttachmentNames", doc) 
0

我注意到你並沒有引述whcih線造成的錯誤。最佳addecrror捕捉到獲取信息上線時出現錯誤:

在程序的頂部(?1號線)..

Sub Click(Source As Button) 
On error goto handler 

在子的底部...

fin: 
exit sub 

handler: 
msgbox "Error " & Error$ & " line " & Erl 
resume fin 

結束Sub

有助於診斷問題。

1

我發現你的代碼存在一些問題。首先,像其他人已經說過的那樣,您需要添加錯誤處理。 其次,使用NotesEmbeddedObject類的Source屬性來獲取附件的原始文件名。當然,您必須自己編寫代碼來處理重複項。

下面是我編寫的程序中的幾行代碼。

Forall i In doc.Items 
    ' *** Locate attachments and detach them 
    If Left$(i.Name,1)<>"$" Or Lcase(i.Name)="$file" Then 
    If i.IsSummary = False Then 
     If Not Isempty(i.EmbeddedObjects) Then 
     If (i.Type = RICHTEXT) Then 
      Forall obj In i.EmbeddedObjects 
      If (obj.Type = EMBED_ATTACHMENT) Then 
       Call obj.ExtractFile(basePath & obj.Source) 
      End If 
      End Forall 
     End If 
     End If 
    End If 
    End If 
End Forall 

程序將導出所有文件在數據庫中以XML,取下任何附件出口任何嵌入式圖像,並連結這些分離/導出文件的XML文件。你可以找到更多關於它在這裏:http://www.texasswede.com/websites/texasswede.nsf/Page/Notes%20XML%20Exporter

0

我是新來的注意事項等等感謝所有輸入上使得代碼更優秀的解決方案!我用下面的代碼運行了一個快速測試,發現它至少可以在一個文檔上運行(對整個數據庫的TBD)。我發現文件名存儲在$ FILE項目的Items中。此代碼獲取文件名然後提取文件:

Dim item As NotesItem 
'assumes first item is $FILE 
Set item = doc.Items(0) 
Dim attachmentName As String 
attachmentName = item.Values(0) 
Write #fileNum%, "attachmentName= ", attachmentName 
Set attachment = doc.GetAttachment(attachmentName) 
Call attachment.ExtractFile _ 
("c:\kcw\" + attachmentName) 
+0

你不能假定$ File是第一項。它並不總是如此。 –