简体   繁体   中英

How to get user permissions on calendar in exchange server using c#

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

Get-MailboxFolderPermission -Identity john@contoso.com:\Calendar -User "test@test.com"

I could not find any way to it without invoking powershell, but it can be done like this:

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];
}

What you are doing, is to actually run the PS command from the code itself.

I also found the EWS api which probably contains what you are looking for.

Getting the current permissions for a folder by using the Bind method.

    // 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM