c# - 如何使用 c# 在 Exchange 服务器中获取用户对日历的权限
问题描述
我在我的 Web 应用程序中使用交换日历。在将事件从我的 Web 应用程序插入到日历以交换服务器之前,我想在我的 c# 端获取该特定日历的用户权限。我通过执行以下 powershell 获得了权限命令。但坚持使用 c# 得到相同的结果。
Get-MailboxFolderPermission -Identity john@contoso.com:\Calendar -User "test@test.com"
解决方案
如果不调用 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);
推荐阅读
- twitter-bootstrap - 如何修复加载资源失败:在 Bootstrap 3 SASS 上加载 Glyphicons 字体时出现 404(未找到)错误
- python - 我无法从 picamera 流式传输图像
- c# - Microsoft Graph 和无用户访问
- python-2.7 - ValueError:形状(1,4)和(5,4)未对齐:4(dim 1)!= 5(dim 0),将我的变量添加到我的预测机器时
- apache-spark - Scala-Spark:过滤 DataFrame 性能和优化
- rest - 403 Forbidden for SharePoint version APIs 但它们在设计时工作并且所有其他 REST 调用工作
- maven - 如何让 Maven 执行器插件不报告依赖收敛错误两次?
- python - 用变换重新替换
- kubernetes - Kubernetes master 不附加 FlexVolume
- javascript - 是否可以将 Proptypes 用于复杂对象的关联数组