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

ASR 651 Reputation points


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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,452 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,521 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,164 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,644 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ChengFeng - MSFT 5,005 Reputation points Microsoft Vendor

    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:

    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

    1 person found this answer helpful.