您可以在FolderId 中指定要访问的日历。
FolderId folderIdFromCalendar = new FolderId(WellKnownFolderName.Calendar, "sharedInbox@example.com");
然后您可以使用folderIdFromCalendar 来检索您想要的日历项目,例如:
FindItemsResults<Item> appointments = ExchangeServive.FindItems(folderIdFromCalendar, ItemView);
请记住,该程序必须在与邮箱共享的用户的上下文中运行。
更新:
如果您碰巧知道FolderId,您可以通过执行以下代码检查当前用户是否有权访问此日历:
如上,你需要初始化一个FolderId:
FolderId folderIdFromCalendar = new FolderId("AQMkADAwATM3ZmYAZS1kNjE0LWU1ZmQtMDACLTAwCgAuAAADJRMtiupYBUGDcKdcqUrr3AEA1/sqwbrwUEeFM0Mc+UBFoQAAABzkm1sAAAA=");
之后,试试下面的代码:
if (folderIdFromCalendar != null)
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}
另一个更新:
if (folderIdFromCalendar != null)
{
if (folderIdFromCalendar.Mailbox.ToString().ToLower() == "your-Mailadress".ToLower())
{
Console.WriteLine("The folder you specified is your own");
}
else
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
Console.WriteLine("You have been given access to this mailbox. Its owner is: " + folderIdFromCalendar.Mailbox.ToString()); //if you need to know, whos mailbox you are accessing right now
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}
最后更新:
我现在已经用谷歌搜索了很多,发现了一些对我有用的东西。但老实说,我并没有完全理解下面代码中的所有内容:
FolderId folderIdFromCalendar = new FolderId("AQMkADAwATM3ZmYAZS1kNjE0LWU1ZmQtMDACLTAwCgAuAAADJRMtiupYBUGDcKdcqUrr3AEA1/sqwbrwUEeFM0Mc+UBFoQAAABzkm1sAAAA=");
Folder folderFromCalendar = Folder.Bind(service, folderIdFromCalendar);
AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, folderFromCalendar.Id.UniqueId, "random@mailadress.com");
AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
var mailbox = ((AlternateId)aiResponse).Mailbox;
if (folderFromCalendar != null)
{
if (mailbox.ToString().ToLower() == "your-Mailadress".ToLower())
{
Console.WriteLine("The folder you specified is your own");
}
else
{
try
{
ItemView cView = new ItemView(1000);
FindItemsResults<Item> appointments = service.FindItems(folderIdFromCalendar, cView);
int count = appointments.TotalCount; //just an example of some random action on the folder calendar
Console.WriteLine("You have been given access to this mailbox. Its owner is: " + mailbox.ToString());
}
catch (ServiceResponseException ex)
{
Console.WriteLine("The specified calendar was not shared with you. \n" + ex);
}
}
}
else
{
Console.WriteLine("The specified calendar ID could not be linked to a calendar folder.");
}
我不明白,字符串“random@mailadress.com”如何影响该程序中的任何内容,但语法需要一个字符串。