我無法通過 c# 訪問 Outlook 中的共享日歷。我嘗試了下面的代碼。但也嘗試遍歷所有檔案夾但沒有成功......
using Outlook = Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;
void test(){
OutlookApp outlookApp = new OutlookApp();
NameSpace mapiNamespace = outlookApp.GetNamespace("MAPI");
//Access my calendar is OK!
MAPIFolder ownerFolder = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
Console.WriteLine("My: count:" ownerFolder.Folders.Count " path:\"" ownerFolder.FullFolderPath "\" items:" ownerFolder.Items.Count);
//ownerFolder.Folders.Count == 0, why?
foreach (MAPIFolder subFolder in ownerFolder.Folders) Console.WriteLine(subFolder.FullFolderPath);
//???Points to my calendar???
Recipient recipient = mapiNamespace.CurrentUser;
MAPIFolder sharedFolder = mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
Console.WriteLine("Shared: count:" sharedFolder.Folders.Count " path:\"" sharedFolder.FullFolderPath "\" items:" sharedFolder.Items.Count);
//sharedFolder.Folders.Count == 0, why?
foreach (MAPIFolder subFolder in sharedFolder.Folders) Console.WriteLine(subFolder.FullFolderPath);
}
預先感謝您的回答。
uj5u.com熱心網友回復:
在以下代碼中,您將本地用戶名傳遞給該GetSharedDefaultFolder
方法:
//???Points to my calendar???
Recipient recipient = mapiNamespace.CurrentUser;
MAPIFolder sharedFolder = mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
NameSpace.GetSharedDefaultFolder方法回傳一個物件,該物件代表指定用戶的指定默認檔案夾。Folder
此方法用于委派方案,其中一個用戶已將一個或多個默認檔案夾(例如,他們的共享Calendar
檔案夾)的訪問權限委派給另一個用戶。因此,您需要傳遞與您共享日歷的人的用戶名(或電子郵件),而不是您的:
Recipient recipient = mapiNamespace.CreateRecipient("Eugene Astafiev");
MAPIFolder sharedFolder = mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
請注意,Recipient
必須決議物件。
Recipient recipient = mapiNamespace.CreateRecipient("Eugene Astafiev");
recipient.Resolve();
if(recipient.Resolved)
{
mapiNamespace.GetSharedDefaultFolder(recipient, OlDefaultFolders.olFolderCalendar);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/435494.html