Download and Upload files via Graph API from SharePoint lists and document libraries. C# .NET6

Amit Singh Rawat 731 Reputation points
2023-08-17T06:12:20.09+00:00

Hi,

I want to download files from my SharePoint Site (Not One Drive). And with the help of GraphServiceClient, I am able to get SiteID, ListID and also itemId.

Now how can I upload and download files to this library with the help of Graph API (GraphServiceClient).

This is how I am creating object of GraphServiceClient;

ClientSecretCredential clientSecretCredential = new(tenantID, clientID, clientSecret);
                GraphServiceClient graphClient = new(clientSecretCredential);
Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-08-18T06:27:02.2833333+00:00

    Hi @ASR

    It is recommended to browse the official documentation here, which provides code examples for your reference:

    Here is Download file:

    // Code snippets are only available for the latest version. Current version is 5.x
    var graphClient = new GraphServiceClient(requestAdapter);
    await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Content.GetAsync();
    

    User's image

    Here is upload file:

    https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

    https://stackoverflow.com/questions/41285403/upload-file-to-sharepoint-drive-using-microsoft-graph


    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.

    Best Regards

    Cheng Feng

    2 people found this answer helpful.

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.