2009-09-18 5 views
2

로터스 노트 이메일 첨부 파일을 파일 시스템으로 추출/내보내기해야합니다. 그것을 위해 나는 다음과 같은 방법하지만 난 (항목에서 NotesItem nItem) 라인 foreach 문에서 오류를 수신하고 각각의 시간을 썼다 .. 사람이C#을 사용하여 Lotus Notes Email에서 첨부 파일 추출/내보내기

public void GetAttachments() 
    { 
     NotesSession session = new NotesSession(); 
     //NotesDocument notesDoc = new NotesDocument(); 
     session.Initialize(""); 

     NotesDatabase NotesDb = session.GetDatabase("", "C:\\temps\\lotus\\sss11.nsf", false); //Open Notes Database 
     NotesView inbox = NotesDb.GetView("By _Author"); 
     NotesDocument docInbox = inbox.GetFirstDocument(); 
     object[] items = (object[])docInbox.Items; 
     **foreach (NotesItem nItem in items)** 
     { 

      //NotesItem nItem = (NotesItem)o1; 
      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:\\temps\\export\\" + fileName); 
       } 
      } 
     } 

답변

2
Jwalin을 .. 내가 뭘 잘못 말해주십시오

감사 수

$ File 항목을 사용하여 첨부 파일 이름을 가져올 필요가 없습니다. 오히려 NotesDocument 클래스의 HasEmbedded 및 EmbeddedObject 속성을 사용할 수 있습니다.

public void GetAttachments() 
    { 
    NotesSession session = new NotesSession(); 
    //NotesDocument notesDoc = new NotesDocument(); 
    session.Initialize(""); 

    NotesDatabase NotesDb = session.GetDatabase("", "C:\\temps\\lotus\\sss11.nsf", false); //Open Notes Database 
    NotesView inbox = NotesDb.GetView("By _Author"); 
    NotesDocument docInbox = inbox.GetFirstDocument(); 

    // Check if any attachments 
    if (docInbox.hasEmbedded) 
    { 
     NotesEmbeddedObject attachfile = (NotesEmbeddedObject)docInbox.embeddedObjects[0]; 

     if (attachfile != null) 
     { 
      attachfile.ExtractFile("C:\\temps\\export\\" + attachfile.name); 
     } 
    } 
0

에드의 해결책이 제대로 작동하지 않았습니다. Notes 데이터베이스 디자인에서 HasEmbedded 플래그가 true 인 경우에도 EmbeddedObjects 속성을 null로 남겨 두었습니다. 그래서 나는 Ed와 Jwalin의 솔루션을 결합하여 Notes 문서에서 모든 첨부 파일을 가져 오도록 수정했습니다.

 NotesDocument doc = viewItems.GetNthEntry(rowCount).Document; 
     if (doc.HasEmbedded) 
     { 
      object[] items = (object[])doc.Items; 
      foreach (NotesItem item in items) 
      { 
       if(item.Name.Equals("$FILE")) 
       { 
       object[] values = (object[])item.Values; 
       doc.GetAttachment(values[0].ToString()).ExtractFile(fileSavePath + values[0].ToString()); 
       } 
      } 
관련 문제