c# - EWS - 访问共享日历项目/约会

标签 c# powershell calendar exchangewebservices

我正在尝试获取共享日历的所有项目(我已关注 Glen Scales 的 EWS - Access All Shared Calendars),但它仅列出“共享日历”下的文件夹(法语为“Calendrierspartagés”,我可以也找不到“Common Views”是否应该本地化,我不这么认为)。

一位同事创建了一个包含一些约会的日历,与我共享,并授予我最大的测试权限(所有权)。

如何访问此共享日历中的项目/约会(在 C#/PowerShell 中)?

更多信息: 推荐使用Folder.Bind,但调用会产生异常:

        ExchangeService service = new ExchangeService(ExchangeVersion.ExchangeVersion);
        service.Credentials = new WebCredentials("login", "****");
        service.Url = new Uri("https://.../ews/exchange.asmx");

        try {
        FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="187b776f776a737d6a587c7775797176367b7775" rel="noreferrer noopener nofollow">[email protected]</a>");
        Folder TargetFolder = Folder.Bind(service, cfolderid);     

        Console.WriteLine("target folder = " + TargetFolder);
        } catch (Exception ex){
            Console.WriteLine(ex.ToString());
        }  

Microsoft.Exchange.WebServices.Data.ServiceResponseException: Le dossier spécifié est introuvable dans la banque  d'informations.                                          
  à Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()                                                                                       
  à Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()                                                                                          
  à Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder(FolderId folderId, PropertySet propertySet)                                                         
  à Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId folderId, PropertySet propertySet)                                                
  à Microsoft.Exchange.WebServices.Data.Folder.Bind(ExchangeService service, FolderId id)                                                                                
 à ConsoleApplication.Program.Main(String[] args)

附录:我用 Glen 的代码重新启动,痕迹显示为注释。 WlinkAddressBookEIDA 为空。

 static Dictionary<string, Folder> GetSharedCalendarFoldersA(ExchangeService service, String mbMailboxname)
{
    Dictionary<String, Folder> rtList = new System.Collections.Generic.Dictionary<string, Folder>();

    FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Root, mbMailboxname);
    FolderView fvFolderView = new FolderView(1000);
    SearchFilter sfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "Common Views");
    FindFoldersResults ffoldres = service.FindFolders(rfRootFolderid, sfSearchFilter, fvFolderView);
    if (ffoldres.Folders.Count == 1)
    {

        PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
        ExtendedPropertyDefinition PidTagWlinkAddressBookEID = new ExtendedPropertyDefinition(0x6854, MapiPropertyType.Binary);
        ExtendedPropertyDefinition PidTagWlinkFolderType = new ExtendedPropertyDefinition(0x684F, MapiPropertyType.Binary);
        ExtendedPropertyDefinition PidTagWlinkGroupName = new ExtendedPropertyDefinition(0x6851, MapiPropertyType.String);

        psPropset.Add(PidTagWlinkAddressBookEID);
        psPropset.Add(PidTagWlinkFolderType);
        ItemView iv = new ItemView(1000);
        iv.PropertySet = psPropset;
        iv.Traversal = ItemTraversal.Associated;

        SearchFilter cntSearch = new SearchFilter.IsEqualTo(PidTagWlinkGroupName, "Calendriers partagés"); // localized
        FindItemsResults<Item> fiResults = ffoldres.Folders[0].FindItems(cntSearch, iv);
        Console.WriteLine("fiResults TotalCount = " + fiResults.TotalCount) ; // OK -> 1
        foreach (Item itItem in fiResults.Items)
        {
            Console.WriteLine("itItem Subject = " + itItem.Subject);  // OK, my coworker shared calendar
            Console.WriteLine("itItem Id = " + itItem.Id); // Id but not the one expected!

                object WlinkAddressBookEIDA = null;
                itItem.TryGetProperty(PidTagWlinkAddressBookEID, out WlinkAddressBookEIDA);
                Console.WriteLine("WlinkAddressBookEIDA = " + WlinkAddressBookEIDA + " is null ? " + (WlinkAddressBookEIDA == null)); // KO -> WlinkAddressBookEIDA =  is null ? True

            try{[...]

最佳答案

I can't find if "Common Views" should is localized either, I don't think so)

您不必使用 EWSEditor 来浏览 Non_IPM 子文件夹,它会以任何一种方式告诉您

A coworker created a calendar with a few appointments, shared it with me and gave me maximum permissions (ownership) for testing. How do you access the Items/Appointments within this shared calendar (in C#/PowerShell)?

如果您知道共享日历的人的电子邮件地址,则只需使用邮箱的FolderId 重载并直接绑定(bind)到它,例如

        FolderId cfolderid = new FolderId(WellKnownFolderName.Calendar, "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91dcf0f8fdf3fee9d1f5fefcf0f8ffbff2fefc" rel="noreferrer noopener nofollow">[email protected]</a>");
        Folder TargetFolder = Folder.Bind(service, cfolderid);

关于c# - EWS - 访问共享日历项目/约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39920641/

相关文章:

java - Calendar.getInstance() 和 GregorianCalendar.getInstance() 之间的区别

c# - 上传 Blob 时 ASP.NET MVC Controller 导致页面重新加载

c# - 模型属性格式

c# - 需要一个好的 ASP.NET 菜单

powershell - Powershell Out-File在文件顶部添加换行符-Out-File与Set-Content

powershell - Nuget 包管理器控制台

javascript - 在 AngularJS 1.x 中单击时在 UI 日历中添加事件

c# - 安装 Windows 服务

powershell - 如何隐藏 Powershell GUI 上的选项卡?

php - 从本周开始使用 Codeigniter 的日历库生成 2 周 View