如何在sharepoint中检查文档的权限 [英] How Do I check Permission on a document in sharepoint

查看:150
本文介绍了如何在sharepoint中检查文档的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在SharePoint中有一个文档。它位于特定的文档集下。 我只有文档的完整网址。现在,用户正在从Web服务请求更新该特定文档。如何在该文档上检查该用户的权限(不在文档集上。因为用户可能没有文档集的权限,只能访问文档)?从文档URL我已实例化SPFile对象。我是否需要将其强制转换为ListItem然后应用DoesUserHavePermission方法?我没有在SPFile对象中找到任何权限检查相关属性。请建议。

Hi,

I have a document in SharePoint. It is placed under a specific document set. I only have the full URL of the document. Now from a web service a user is requesting to update that particular document. How can I check the permission of that user on that document (Not on Document Set. Because the user may not have permission to the document set but only to the document)? From the document URL I have instantiate a SPFile object. Do I need to cast it to a ListItem and then apply DoesUserHavePermission method? I have not found any permission checking related properties in SPFile object. Please suggest.

推荐答案

根据你对这个问题的看法,我的建议对你来说似乎很奇怪,但请尽量考虑它,因为它可以真的很帮助你。



这就是:为什么你认为你应该检查权限?在大多数应用程序代码中,这些事情显然超出了范围。首先,你应该避免使用随机目录,只使用专为每个帐户保留的用户数据设计的目录。



但主要的是完全不同。如今,许多学生都学习了防御性编程:在做某事之前,检查一下你是否可以做到。在许多情况下,应该这样做,并且在许多其他情况下,这是非常错误的,过时的和低效的方法。通常,编程应该冒犯:只是做操作,不要问你是否可以。你总是可以在try-catch下执行代码(通常你应该这样做),让异常传播并最终处理它。如果由于访问冲突而被抛出异常并被捕获,则您没有超出部分。是不是很简单?



-SA
With your thinking you do about this problem, my advice may seem to be weird to you, but please try to think about it, as it can really help you.

Here is the thing: why do you think you should ever check up the permissions? In most of application code, such things are clearly out of the scope. First of all, you should avoid using random directories and use only those specially designed for user data reserved per account.

But main thing is completely different. Many students these days are taught defensive programming: before doing something, check up if you can do it. In many cases, this should be done, and, in many other cases, this is quite wrong, obsolete and inefficient approach. Very often, programming should be offensive: just do the operation, don't ask if you can. You can always execute code under try-catch (and most usually you should), let the exception propagate and eventually handle it. If exception was thrown due to access violation and caught, you don't have the excess. Isn't that simple?

—SA


这篇关于如何在sharepoint中检查文档的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆