【问题标题】:How to check SharePoint document permissions?如何检查 SharePoint 文档权限?
【发布时间】:2010-01-14 02:43:43
【问题描述】:

我在 SharePoint 中部署了一个自定义 Web 服务,该 Web 服务的 Web 方法需要一个 SharePoint docuentUri 作为参数。由于它部署在 SharePoint 环境中,我完成了 SharePoint 身份验证,但这里的问题是,我如何检查请求特定文档的用户是否被授权?换句话说,如果用户没有查看文档的权限,Web 服务方法应该返回一些未经授权的异常吗?我所拥有的只是作为输入参数传递的 SharePoint documentUri。

谢谢。

【问题讨论】:

    标签: moss sharepoint-2007


    【解决方案1】:

    假设您的 Web 服务部署在 SharePoint 网站的 /_vti_bin 虚拟目录中的 SharePoint 上下文中,您可以使用如下所示的 SharePoint 对象模型来检查调用用户是否对您的文档具有特定权限。不幸的是,如果检查失败,CheckPermissions 调用将抛出 UnauthorizedException,因此必须将其捕获。

    string uri = "http://localhost/Shared%20Documents/Document1.doc";  //full path to doc
    using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite(uri))
    using (Microsoft.SharePoint.SPWeb web = site.OpenWeb())
    {
     Microsoft.SharePoint.SPListItem item = web.GetListItem(uri); 
     item.CheckPermissions(Microsoft.SharePoint.SPBasePermissions.OpenItems);
    } 
    

    希望这会有所帮助,

    史蒂夫

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2011-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多