ASP.NET Core SharePoint file provider

10 Oct 20243 minutes to read

The ASP.NET Core SharePoint file provider allows users to access and manage files within Microsoft SharePoint. To get started, clone the SharePoint ASP.NET Core File Provider using the following command.


git clone https://github.com/SyncfusionExamples/sharepoint-aspcore-file-provider  sharepoint-aspcore-file-provider

cd sharepoint-aspcore-file-provider

Prerequisites

To set up the SharePoint service provider, follow these steps:

  1. Create an App Registration in Azure Active Directory (AAD):
    • Navigate to the Azure portal and create a new app registration under Azure Active Directory.
    • Note down the Tenant ID, Client ID, and Client Secret from the app registration.
  2. Use Microsoft Graph Instance:
    • With the obtained Tenant ID, Client ID, and Client Secret, you can create a Microsoft Graph instance.
    • This instance will be used to interact with the SharePoint document library.
  3. Use Details from appsettings.json:
    • The SharePointController is already configured to use the credentials provided in the appsettings.json file.
    • You only need to provide your Tenant ID, Client ID, Client Secret, User Site Name, and User Drive ID in the appsettings.json file, and the application will automatically initialize the SharePoint service.

Example appsettings.json Configuration

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "SharePointSettings": {
    "TenantId": "<--Tenant Id-->",
    "ClientId": "<--Client Id-->",
    "ClientSecret": "<--Client Secret-->",
    "UserSiteName": "<--User Site Name-->",
    "UserDriveId": "<--User Drive ID-->"
  },
  "AllowedHosts": "*"
}

Replace “<–User Site Name–>”, “<–User Drive ID–>”, “tenantId”, “clientId”, and “clientSecret” with your actual values.

After configuring the SharePoint file provider, build and run the project. Now, the project will be hosted in http://localhost:{port} and just mapping the ajaxSettings property of the File Manager component to the appropriate controller methods allows to manage the files in the Microsoft SharePoint.

@* Initializing File Manager with ASP.NET Core service *@

@* Replace the hosted port number in the place of "{port}" *@

<SfFileManager TValue="FileManagerDirectoryContent">
    <FileManagerAjaxSettings Url="http://localhost:{port}/api/SharePointProvider/SharePointFileOperations"
                             UploadUrl="http://localhost:{port}/api/SharePointProvider/SharePointUpload"
                             DownloadUrl="http://localhost:{port}/api/SharePointProvider/SharePointDownload"
                             GetImageUrl="http://localhost:{port}/api/SharePointProvider/SharePointGetImage">
    </FileManagerAjaxSettings>
</SfFileManager>

To perform file operations (Read, Create, Rename, Delete, Get file details, Search, Copy, Move, Upload, Download, GetImage) in the Syncfusion Blazor File Manager component using the ASP.NET Core SharePoint file provider, you need to initialize the SharePoint service in the controller.

To initialize a local service with the above-mentioned file operations, create a new folder named Controllers inside the server part of the project. Then, create a new file with the extension .cs inside the Controllers folder and add the necessary file operations code available in the SharePointProviderController.cs found at this link. Additionally, you can check out all the necessary file operation method details for this provider in the same GitHub repository.

NOTE

To learn more about file actions that can be performed with ASP.NET Core SharePoint file provider, refer to this link