Sharepoint“访问被拒绝......”在load fillversioncollection之后执行executequery时 [英] Sharepoint "access denied..." when executing executequery after load fillversioncollection

查看:95
本文介绍了Sharepoint“访问被拒绝......”在load fillversioncollection之后执行executequery时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我的智慧结束了这个。



接收访问被拒绝。您无权执行此操作或访问此资源。错误,但仅在尝试获取FileVersionCollection时。如果省略oclientContext.Load(文件转换),则工作正常。



为什么凭证适用于文件,但加载FileVersionCollection时却没有?



我尝试过:



使用oclientContext作为ClientContext = New ClientContext(< sharepointsite>)
Dim f As Microsoft.SharePoint.Client.File
Dim fileversions As FileVersionCollection

尝试
f = oclientContext.Web.GetFileByServerRelativeUrl (/+ e.CommandArgument.ToString())
fileversions = f.Versions
oclientContext.Load(f)
oclientContext.Load(fileversions)//如果我省略这个,工作正常
oclientContext.ExecuteQuery()

Catch sp_ex As Microsoft.SharePoint.Client.ServerException
Context.Response.ContentType =text / plain
如果sp_ex.ServerErrorT ypeName =System.IO.FileNotFoundException然后
f = Nothing
Context.Response.Write(找不到文件)
否则
Context.Response.Write(sp_ex.ServerErrorTypeName) )
结束如果
退出Sub

Catch ex As Exception
f = Nothing
Context.Response.ContentType =text / plain
Context.Response.Write(ex.InnerException.Message)
退出Sub

结束尝试

结束使用

解决方案

完全可以拥有读取,修改和删除文件的权限,但无权查看版本。例如,Restricted Read允许您查看和打开项目,但不允许查看版本。



了解SharePoint中的权限级别 - Office支持 [ ^ ]



您需要与SharePoint管理员联系,以查看授予您的代码执行的帐户的权限。


与大多数需要永远解决的问题一样,解决方案很简单。 (虽然我发现很多非常复杂的方法来处理同样的事情;但是没有用)



问题是子网站。

需要在ClientContext中包含子网站。



在我的情况下,我需要从存储的 fileurl 中动态确定子网站控件的 e.CommandArgument



 Dim subsite As String = Regex.Match(e.CommandArgument。 ToString(),。*?(?= \ /),RegexOptions.IgnoreCase).ToString()
使用oclientContext作为ClientContext = New ClientContext(https://< sharepointsite> /+ subsite )


Hello folks, at my wits end on this one.

Receiving "Access denied. You do not have permission to perform this action or access this resource." error but only when attempting to acquire FileVersionCollection. Works fine if I omit the oclientContext.Load(fileversions).

Why would credentials work for the file, but not when loading the FileVersionCollection?

What I have tried:

Using oclientContext As ClientContext = New ClientContext("<sharepointsite>")
            Dim f As Microsoft.SharePoint.Client.File
            Dim fileversions As FileVersionCollection

            Try
                f = oclientContext.Web.GetFileByServerRelativeUrl("/" + e.CommandArgument.ToString())
                fileversions = f.Versions
                oclientContext.Load(f)
                oclientContext.Load(fileversions) //Works fine if I omit this
                oclientContext.ExecuteQuery()

            Catch sp_ex As Microsoft.SharePoint.Client.ServerException
                Context.Response.ContentType = "text/plain"
                If sp_ex.ServerErrorTypeName = "System.IO.FileNotFoundException" Then
                    f = Nothing
                    Context.Response.Write("File Not Found")
                Else
                    Context.Response.Write(sp_ex.ServerErrorTypeName)
                End If
                Exit Sub

            Catch ex As Exception
                f = Nothing
                Context.Response.ContentType = "text/plain"
                Context.Response.Write(ex.InnerException.Message)
                Exit Sub

            End Try

        End Using

解决方案

It's perfectly possible to have permission to read, modify and delete a file, but not have permission to view the versions. For example, "Restricted Read" gives you permission to view and open items, but not to view the versions.

Understanding permission levels in SharePoint - Office Support[^]

You'll need to check with your SharePoint administrator to see what permissions are granted to the account your code is executing as.


As with most problems that take forever to figure out, the solution is simple. (Though I found plenty of very complex ways of addressing the same thing; but didn't work)

The problem was subsites.
Need to include the subsite in the ClientContext.

In my case, I needed to determine the subsite dynamicaly from the fileurl which is stored in the e.CommandArgument of a control.

Dim subsite As String = Regex.Match(e.CommandArgument.ToString(), ".*?(?=\/)", RegexOptions.IgnoreCase).ToString()
        Using oclientContext As ClientContext = New ClientContext("https://<sharepointsite>/" + subsite)


这篇关于Sharepoint“访问被拒绝......”在load fillversioncollection之后执行executequery时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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