Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 16-Jun-17 8:41am
Comments
Member 13250972 12-Jun-17 8:58am    
Anyone?

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.
 
Share this answer
 
Comments
Member 13250972 13-Jun-17 15:05pm    
Admin set permissions to "Read"; which was previously set to "Restricted Read"...but no joy.

Admin said it could take a while to change, but I've waited about two hours.
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)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900