代码之家  ›  专栏  ›  技术社区  ›  David

如何使用c在exchange服务器中获取日历的用户权限#

  •  1
  • David  · 技术社区  · 4 年前

    我正在我的web应用程序中使用exchange日历。在将事件从我的web应用程序插入到exchange服务器的日历之前,我想在c#端获取该特定日历的用户权限。我通过执行以下powershell命令获得了权限。但坚持使用c#获得相同的结果。

    Get-MailboxFolderPermission -Identity john@contoso.com:\Calendar -User "test@test.com"
    
    1 回复  |  直到 4 年前
        1
  •  0
  •   Athanasios Kataras    4 年前

    如果不调用powershell,我找不到任何方法,但可以这样做:

    var runspace = RunspaceFactory.CreateRunspace();
    runspace.Open();
    
    object psSessionConnection;
    
    // Create a powershell session for remote exchange server
    using (var powershell = PowerShell.Create())
    {
        var command = new PSCommand();
        command.AddCommand("Get-MailboxFolderPermission");
        command.AddParameter("Identity", "john@contoso.com:\Calendar");
        command.AddParameter("User", "test@test.com"));
        powershell.Commands = command;
        powershell.Runspace = runspace;
    
        var result = powershell.Invoke();
        psSessionConnection = result[0];
    }
    

    您正在做的是从代码本身实际运行PS命令。

    我也发现了 EWS api 其中可能包含您要查找的内容。

    使用Bind方法获取文件夹的当前权限。

        // Create a property set to use for folder binding.
        PropertySet propSet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.Permissions);
        // Bind to the folder and get the current permissions. 
        // This call results in a GetFolder call to EWS.
        Folder sentItemsFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "test@test.com"), propSet);