2009-09-16 125 views
1

我試圖訪問附件名稱形式「$文件」(Lotus Notes)。

NotesView inbox = _serverDatabase.GetView("($Inbox)"); 
NotesDocument docInbox = inbox.GetFirstDocument(); 

NotesItem file = docInbox.GetFirstItem("$File"); 

String fileType = file.type.ToString(); 

(獲得包含郵件附件的fileType價值 「附件」)

,我沒有得到解決方案中給出:

How to Access attachments from Notes mail?

我得到的解決方案爲:

object[] items = (object[])docInbox.Items; 

foreach (NotesItem nItem in items) 

{ 

    if (nItem.Name == "$FILE") 
    { 

    NotesItem file = docInbox.GetFirstItem("$File"); 

    string fileName = ((object[])nItem.Values) [0].ToString(); 

    NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(fileName); 

    if (attachfile != null) 
     { 
     attachfile.ExtractFile("C:\\test\\" + fileName); 
     } 
} 

但我在這裏只獲得第一個附件值。 任何人都可以幫我解決這個問題嗎?

+1

「管理者標誌」用於管理支持,不是對緊急問題的回答。 – 2009-09-17 15:33:42

回答

3

嘗試這樣:

NotesView inbox = _serverDatabase.GetView("($Inbox)"); 
    NotesDocument docInbox = inbox.GetFirstDocument(); 
    if(docInbox.HasEmbedded) { 
     foreach (NotesEmbeddedObject o in docInbox.EmbeddedObjects) { 
      if (o.Type == 1454) { 
      o.ExtractFile("c:\samples\" & o.Source)  
    } 
    } 
} 

這裏是到Lotus Notes Designer幫助的鏈接 - 真不錯,你可以搜索類等,以找出你有哪些選擇。

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.help.domino.designer85.doc/DOC/H_WHAT_S_NEW_IN_RNEXT_CHAP.html

顯示你所有的方法和各種類的屬性。


Preeti你好,從另一個代碼示例

OK你返回一個數組:

string fileName = ((object[])nItem.Values) [0].ToString(); 

然而,你只選擇第一個值,你需要通過收集遞歸。

嘗試類似這樣的東西。

foreach (object attachment in (object[])nItem.Values) 
     { 
      NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.GetAttachment(attachment.ToString()); 

      if (attachfile != null) 
      { 
       attachfile.ExtractFile("C:\\test\\" + attachment.ToString()); 
      } 

     } 

喬希

+0

嗨馬修斯, 我收到以下錯誤::( 錯誤1:foreach語句無法在類型「對象」的變量操作,因爲「對象」不包含「的GetEnumerator」 \t 錯誤2一個公共定義:Domino.NotesEmbeddedObject」不包含定義‘類型’ 錯誤3:操作員‘和’不能應用於類型的操作數‘串’和‘串’\t 請幫我解決這個問題 – Preeti 2009-09-16 12:29:31

+1

也許你。可以首先使用NotesEmbeddedObject [] embobjs = docInbox.EmbeddedObjects獲取NotesEmbeddedObjects的數組;然後使用foreach循環或for循環來處理embobjs數組中的所有對象。另外,第三個錯誤是因爲在C#中&操作符和Lotuss中的操作符不同。您需要使用+運算符來連接字符串。 – 2009-09-16 13:18:04

0

你上面的代碼片斷是對我很有幫助。所以,我試着保存所有附件並最終找到了下面的解決方案。

  NotesView nInboxDocs = NDb.GetView("$Inbox"); 
      NDoc=nInboxDocs.GetFirstDocument(); 
      while (NDoc != null) 
      { 
       if (NDoc.HasEmbedded && NDoc.HasItem("$File")) 
       { 
        // To save only first attachment // 
        //pAttachment = ((object[])NDoc.GetItemValue("$File"))[0].ToString(); 
        //pAttachment = CurItem.ToString(); 
        //NDoc.GetAttachment(pAttachment).ExtractFile(@"C:\Documents and Settings\Administrator\Desktop\" + pAttachment); 

        // To save all attachment // 
        object[] AllDocItems = (object[])NDoc.Items; 
        foreach (object CurItem in AllDocItems) 
        { 
         NotesItem nItem = (NotesItem)CurItem; 
         if (IT_TYPE.ATTACHMENT == nItem.type) 
         { 
          pAttachment = ((object[])nItem.Values)[0].ToString(); 
          NDoc.GetAttachment(pAttachment).ExtractFile(@"C:\Documents and Settings\Administrator\Desktop\" + pAttachment); 
         } 
        } 
       } 
       NDoc = nInboxDocs.GetNextDocument(NDoc); 
      } 
相關問題