none
Retrieve folder/files from documents folder results in UnauthorizedAccessException RRS feed

  • Question

  • Hello,

    On developing Sharepoint add-in in my MVC web I followed all steps to create SP developement site (where I am owner)   the app-addin and created some folders and files for testing in the documents folder.

    Image shows the SP path does exists


    Now I want to list the files/folders in my Webpage to show to user:


    I use this code to get the proper folder contents:

    But on retrieving folder where _spfolder = "/sites/ontwikkel/Gedeelde  documenten/Contracten/2016/16C022"

    Folder  SPFolder = SpWeb.GetFolderByServerRelativeUrl(_spfolder);
    FoldersCollection SPFolders = SPFolder.Folders;
    FileCollection SPFiles = SPFolder.Files;
    clientContext.Load(SPFolder);
    clientContext.Load(SPFolders);
    clientContext.Load(SPFiles);
                        try
                        {
                            clientContext.ExecuteQuery();
                        }
                        catch (Exception e)
                        {
                        }


    ..

    I get an UnauthorizedAccessException error although i am the owner and my context.web.currentuser is correct.

    How can i solve this issue ?




    • Edited by ermoll Saturday, December 24, 2016 11:25 AM image missing
    Saturday, December 24, 2016 11:23 AM

All replies

  • Hi,

    Try to grant the add-in with proper permission.

    Below is what I tested:

    Test code:

    var _spfolder = "/sites/dev/Shared%20Documents/Folder";
    
    
                        Folder SPFolder = clientContext.Web.GetFolderByServerRelativeUrl(_spfolder);
                        FolderCollection SPFolders = SPFolder.Folders;
                        FileCollection SPFiles = SPFolder.Files;
                        clientContext.Load(SPFolder);
                        clientContext.Load(SPFolders);
                        clientContext.Load(SPFiles);
                        try
                        {
                            clientContext.ExecuteQuery();
                        }
                        catch (Exception e)
                        {
                        }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, December 26, 2016 2:37 AM
  • Thanks...that was the solution to set the permission !
    Tuesday, December 27, 2016 11:16 AM
  • Hi,

    You could mark the reply as answer if the reply helped you, it may help others who has similar issue.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, December 28, 2016 1:29 AM