2013-03-13 77 views
0

我正在開發一個WPF-C#應用程序並使用Redemption獲取MS Outlook 2010聯繫人項目。如果我的Outlook只有一個SMTP帳戶,它工作正常。但是,如果我配置另一個帳戶是交換服務器帳戶,那麼我不會從同一代碼中獲得任何聯繫人項目。以下是我的代碼:未從Outlook 2010獲取聯繫人項目

 Interop.Redemption.RDOItems folderItems = null; 
     Interop.Redemption.RDOFolder folderContacts = null; 
     Interop.Redemption.RDOFolder folderSuggestedContacts = null; 
     List<GMContactItem> allOutlookContacts = null; 
     object itemObj = null; 
     List<Interop.Redemption.RDOContactItem> contactItemsList = null; 

     try 
     { 

      folderContacts = (RDOFolder)RDOSessionItem.GetDefaultFolder(Interop.Redemption.rdoDefaultFolders.olFolderContacts); 
      contactItemsList = new List<RDOContactItem>(); 
      folderItems = folderContacts.Items; 
      for (int i = 1; folderItems.Count >= i; i++) 
      { 
       itemObj = folderItems[i]; 
       if (itemObj is Interop.Redemption.RDOContactItem) 
        contactItemsList.Add(itemObj as RDOContactItem); 
       else 
        Marshal.ReleaseComObject(itemObj); 
      } 

      Marshal.ReleaseComObject(folderItems); 
      folderItems = null; 


      // getting items from the Suggested Contacts folder in Outlook 
      folderSuggestedContacts = RDOSessionItem.GetDefaultFolder(
             rdoDefaultFolders.olFolderSuggestedContacts); 
      if (folderSuggestedContacts != null) 
      { 
       folderItems = folderSuggestedContacts.Items; 
       for (int i = 1; folderItems.Count >= i; i++) 
       { 
        itemObj = folderItems[i]; 
        if (itemObj is Interop.Redemption.RDOContactItem) 
         contactItemsList.Add(itemObj as Interop.Redemption.RDOContactItem); 
        else 
         Marshal.ReleaseComObject(itemObj); 
       } 
      } 
     } 
     catch (System.Exception ex) 
     { 
      System.Windows.Forms.MessageBox.Show(ex.ToString()); 
     } 

當我刪除我的Exchange服務器的帳戶,然後它做工精細,如果我在Outlook中添加Exchange服務器帳戶,然後這個代碼有沒有例外,但不給任何聯繫人項目。任何人都可以建議我這裏可能是什麼問題。提前致謝。

-Surya

+1

Exchange郵箱中的聯繫人文件夾是否包含任何項目? – 2013-03-13 13:47:15

+0

嗨德米特里,基本上我正在與兩個帳戶之一是SMPT和其他交換服務器。是的,我的交換郵箱中有聯繫人,因爲當我打開選擇名稱對話框時,它包含許多聯繫人。除此之外,第二個帳戶是SMTP帳戶,在通訊簿中也有很多聯繫人。另外,如果我使用outlook 2007運行相同的應用程序,那麼它運行良好。 – 2013-03-13 16:22:14

回答

0

你在看GAL條目嗎?這些地址條目存在於GAL(基於AD)中,不在Exchange郵箱的「聯繫人」文件夾中。

如果您需要打開(非默認)PST存儲的聯繫人文件夾,請調用RDOStore.GetDefaultFolder(olFolderContacts)而不是RDOSession.GetDefaultFolder(它從默認存儲返回文件夾)。

可以使用RDOSession.Stores集合打開輔助PST存儲。