This .NET 9 project demonstrates how to perform file operations in SharePoint Online using the Microsoft Graph API with OAuth 2.0 authentication and delegated access. The application facilitates seamless file interactions, leveraging modern authentication techniques and the capabilities of the Graph API.
- OAuth 2.0 authentication with delegated access.
- File operations on SharePoint Online, such as:
- Uploading files
- Downloading files
- Deleting files
- Listing files
- Easy-to-use interface for managing files in SharePoint document libraries.
Before running the application, ensure you have the following:
- A Microsoft 365 tenant with SharePoint Online enabled.
- Azure Active Directory (AAD) App Registration:
- Client ID
- Tenant ID
- Client Secret
- Redirect URI configured for OAuth 2.0 authentication.
- Permissions granted in Azure AD App Registration for Microsoft Graph API:
Sites.ReadWrite.All
Files.ReadWrite.All
- Visual Studio 2022 or later.
- .NET 9 SDK installed.
git clone https://github.com/nitin27may/sharepoint-graph-api
cd sharepoint-graph-api
- Open the
appsettings.json
file and update the placeholders with your Azure AD App Registration details:{ "GraphApiSettings": { "ClientId": "<YOUR-CLIENT-ID>", "TenantId": "<YOUR-TENANT-ID>", "ClientSecret": "<YOUR-CLIENT-SECRET>", "Scope": "https://graph.microsoft.com/.default ", "BaseGraphUri": "https://graph.microsoft.com/v1.0", "BaseSpoSiteUri": "<YOUR-BASE-SHAREPOINT-SITE-Name>.sharepoint.com" } }
- Open the project in Visual Studio.
- Restore NuGet packages:
dotnet restore
- Build the solution:
dotnet build
- Run the application:
dotnet run
Note: We are using Bruno API client for the testing Rest API, the files are added in Api Collection Folder
- This project has
GraphApiCientFactory
which is handling the authentication. - Upon successful authentication, the application will obtain an access token to interact with SharePoint Online via the Graph API.
Please pass root
as siteName if you are using base SPO site.
- Select the document library where you want to upload the file.
- Provide the file path or use the file picker to select the file.
- Click
Upload
to upload the file to SharePoint Online.
- Select the file you want to download from the list of files.
- Click
Download
to save the file locally.
- Select the file you want to delete from the list of files.
- Click
Delete
to remove the file from SharePoint Online.
- The application automatically fetches and displays the files in the selected document library.
- .NET 9
- Microsoft Graph API
- OAuth 2.0 Authentication
- Azure Active Directory
- SharePoint Online
Contributions are welcome! If you find a bug or have a feature request, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries or support, please contact nitin27may@gmail.com.