如何使用Exchange EWS API仅检索共享日历。
我如何知道使用Exchange EWS API共享哪个日历。
答案 0 :(得分:2)
您只需在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.");
}
我不明白,字符串&#34; random@mailadress.com"影响该程序中的任何内容,但语法需要一个字符串。