2009-03-31 4 views
1
난이 "간단한"아웃룩 객체가

에서 Outlook.Folder 객체 생성 :에하우투 Outlook.Application.ActiveExplorer.CurrentFolder

Outlook.Explorer olExplorer = this.Application.ActiveExplorer(); 

을 "ThisAddin_StartUp는"나는에 olExplorer.FolderSwitch 이벤트를 등록 function olExplorer_FolderSwitch().

Outlook.Folder f = olExplorer.CurrentFolder as Outlook.Folder; 

을 :하지만이 내가 현재 폴더에서 아웃룩 폴더 개체를 만들어야합니다 재산 "CurrentFolder는"타입 MAPIFolder이며 Outlook.Folder로 사용할 수 캔트. 어떻게 CurrentFolder- 속성을 Outlook.Folder에 "캐스팅"할 수 있습니까? - 이벤트 처리기를 잃어 버리지 않고? 난이 간단한 변환 개체를 할 경우 f를 행사 BeforeItemMove을 발생하지 않습니다 - F 이 NULL이기 때문에 olExplorer.CurrentFolder가

답변

0

없는 경우에는 정말 가에 따라 같은 문제를하지 않습니다 설명서 Explorer.CurrentFolder는 MAPIFolder가 아닌 Outlook.Folder 형식의 개체를 반환합니다. 필자는 개인적으로 VSTO (2007 특정) 개발을하지 않았지만 다른 버전의 개체 모델을 섞어 놓지 않았습니까?

어쨌든 Outlook.Folder 및 MAPIFolder는 EntryID 및 StoreID 속성을 공유합니다. 이들을 사용하여 NameSpace.GetFolderFromID을 사용하여 해당 Outlook.Folder를 조회 할 수 있습니다. 문제의 네임 스페이스는 Application.GetNamespace ("MAPI")를 통해 가져옵니다.

+0

Explorer.CurrentFolder는 MAPIFolder 형식의 개체를 반환합니다. – Vasyl

1

쉬운 방법을 찾지 못했습니다. 폴더 세션에서 Outlook.Folder를 찾을 수 있습니다.

EntryID를 비교하면 올바른 폴더를 얻을 수 있습니다.

Outlook.Folders olFolders = OutlookApp.Session.Folders; 

for (int i = 1; i <= olFolders.Count; i++) 
{ 
    if (olFolders[i].EntryID == olExplorer.CurrentFolder.EntryID) 
    { 
     // folder found assign and use it. 
    } 
} 

1에서 시작하고 같거나 그보다 작은 수로 모든 폴더를 가져옵니다.

Outlook.Explorer olExplorer = this.Application.ActiveExplorer(); 
Outlook.Folder f = (Outlook.Folder)olExplorer.CurrentFolder; 
1

명시 적 캐스트를 시도 Outlook.Folder 쉬운 방법의 변환 MAPIFolder있다.

0

Outlook.Folder가 Outlook.MAPIFolder과 동일합니다 :