how to get file level user access information from a sharepoint site, for folders and subfolders in the site, in python using sharepoint api

Taranath Sistla 0 Reputation points
2024-08-12T10:44:19.8866667+00:00

We are working on a feature, which users have access to a file in a SharePoint folder, and we need this details from a site perspective.

for example a site can have multiple folders, sub folders and files, we need a SharePoint API to fetch these details for all the files inside the site.

If any one has worked on it please suggest for any API

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,006 Reputation points Microsoft External Staff
    2024-08-13T02:08:37.3533333+00:00

    Hi @Taranath Sistla

    I would recommend you to use Office365-REST-Python-Client to get list item. You could refer to following code

    """
    Gets the files from the folder.
    If 'recursive' flag set to True, it traverses all sub folders
    """
    from office365.sharepoint.client_context import ClientContext
    from office365.sharepoint.files.file import File
    from tests import test_team_site_url, test_user_credentials
    def print_file(f):
        # type: (File) -> None
        print(f.serverRelativeUrl)
    ctx = ClientContext(test_team_site_url).with_credentials(test_user_credentials)
    target_folder_url = "Shared Documents"
    root_folder = ctx.web.get_folder_by_server_relative_path(target_folder_url)
    files = root_folder.get_files(True).execute_query()
    [print_file(f) for f in files]
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.