1

I have a SharePoint where I can do (CRUD) operations in the browser on a particular folder. I am trying to get all the folders using C# code

// Test code
                try
                {
                    ClientContext context = new ClientContext(url);
                    context.Credentials = new SharePointOnlineCredentials("username", GetSecureString("password"));
                    Web sites = context.Web;
                    context.Load(sites, website => website.Folders);
                    Folder folders = sites.RootFolder;
                    context.ExecuteQuery();
                    Console.Out.WriteLine(folders.Folders.Count);
                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine(e.Message); Console.ReadLine();
                }

I got an exception

"Access denied. You are not authorized to perform this action or access this resource.".

Can anyone help me out how to solve the issue?

  • I fail to see the accessing of REST. Does the user whose credentials you are providing have access to the library and folder? Is this a SharePoint app? You have it tagged, but at the same time, you state you are accessing a REST resource when you are not, so I want to clarify that. If you are in an app, verify that the app has appropriate permissions. – wjervis Jan 25 '16 at 18:06
  • Sorry if this seems too basic but just to get it out of the way: Did you attempt whatever action you're doing in a normal browser, as the user you're plugging in, to make sure permissions are correct? – Pete M Jan 25 '16 at 18:41
0

Make sure you have read permissions on the site. If you already have them, then try to assign yourself "colaborate" permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.