Sharepoint.Http.Data.Connector 1.0.2

Suggested Alternatives

SharePoint.Http.Connector.Core

Additional Details

This package was updated and redirected to another repository. I recommend to uninstall this library and install the alternative package.

dotnet add package Sharepoint.Http.Data.Connector --version 1.0.2
                    
NuGet\Install-Package Sharepoint.Http.Data.Connector -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sharepoint.Http.Data.Connector" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sharepoint.Http.Data.Connector" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Sharepoint.Http.Data.Connector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sharepoint.Http.Data.Connector --version 1.0.2
                    
#r "nuget: Sharepoint.Http.Data.Connector, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sharepoint.Http.Data.Connector@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sharepoint.Http.Data.Connector&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Sharepoint.Http.Data.Connector&version=1.0.2
                    
Install as a Cake Tool

Sharepoint http data connector

Sharepoint http data connector is a library that can help us manage API calls to our sites on Sharepoint. Provides a list of features that are useful for this integration.

Overview

Sharepoint http data connector is an Open-Source project, remember that you can support it if you want.

During the documentation you will se that is simple the implementation of this library, and can help you to much when you need to apply a custom integration with a site in Sharepoint.

Before to start, remember that there is some information that is very important to have to use the library. The data that we need is the following:

  • Authentication information:

    • AuthenticationUrl
    • TenantId
    • ClientId
    • ClientSecret
    • GrantType
    • Resource
  • Sharepoint instance information:

    • SharepointSiteId
    • SharepointSiteName
    • SharepointInstanceUrl
    • SharepointSiteUrl
    • ServerRelativeUrl

Unfortunately, the current authentication type that support this library is client_credentials, but I foresee to incorporate different ways to authenticate in the future.

If you don't know how to recover this information, don't worry!!
You can find all the information that you need with the following link(s):

Documentation

We can implement the use of this library for different kind of projects, for example a sample demo or with ASP.NET Core.

Sample implementation

To implement this library, one option is only making an instance to the class SharepointDataContext as shown below:

    SharepointDataContext sharepointContext = new SharepointDataContext(new SharepointContextConfiguration
    {
        // Authentication for SharePoint configuration.
        AuthenticationUrl = "https://accounts.accesscontrol.windows.net/{tenantid}/",
        TenantId = "00000000-0000-0000-0000-000000000000",
        ClientId = "00000000-0000-0000-0000-000000000000@00000000-0000-0000-0000-000000000000",
        ClientSecret = "{client_secret}",
        GrantType = "client_credentials",
        Resource = "00000003-0000-0ff1-ce00-000000000000/{your_organization}.sharepoint.com@{tenantid}",
        // Rest API to sharepoint site configuration.
        SharepointSiteId = "00000000-0000-0000-0000-000000000000",
        SharepointSiteName = "{site_name}",
        SharepointInstanceUrl = "https://{your_organization}.sharepoint.com/",
        SharepointSiteUrl = "https://{your_organization}.sharepoint.com/sites/{your_site}",
        ServerRelativeUrl = "/sites/{your_site}/" | "/sites/{your_site}/{library_folder_path}/" | "/"
    });

The class SharepointContextConfiguration contains the main information to connect correctly with an instance of SharePoint.

ASP.NET Core implementation

As the previous example, the implementation in ASP.NET Core project is similar, we only need to register our service in our class program.cs as is shown in the following script.

    builder.Services.AddScoped<ISharepointDataContext>(s => new SharepointDataContext(new SharepointContextConfiguration
    {
        // Authentication for SharePoint configuration.
        AuthenticationUrl = builder.Configuration.GetSection("SharepointSite:Authentication:authenticationUrl").Value,
        TenantId = builder.Configuration.GetSection("SharepointSite:Authentication:tenantId").Value,
        ClientId = builder.Configuration.GetSection("SharepointSite:Authentication:clientId").Value,
        ClientSecret = builder.Configuration.GetSection("SharepointSite:Authentication:clientSecret").Value,
        GrantType = builder.Configuration.GetSection("SharepointSite:Authentication:grantType").Value,
        Resource = builder.Configuration.GetSection("SharepointSite:Authentication:resource").Value,
        // Rest API to SharePoint site configuration.
        SharepointSiteId = builder.Configuration.GetSection("SharepointSite:RestAPI:id").Value,
        SharepointSiteName = builder.Configuration.GetSection("SharepointSite:RestAPI:name").Value,
        SharepointInstanceUrl = builder.Configuration.GetSection("SharepointSite:RestAPI:resource").Value,
        SharepointSiteUrl = builder.Configuration.GetSection("SharepointSite:RestAPI:site").Value,
        ServerRelativeUrl = builder.Configuration.GetSection("SharepointSite:RestAPI:serverRelativeUrl").Value
    }));

Note: To have a better structure in our code, we can add this service as an extension method.

In our Controller class we need to add the following code to make use of Dependency Injection with this library.

    public class ExampleController : ControllerBase
    {
        private readonly ISharepointDataContext _sharepointContext;

        public ExampleController(ISharepointDataContext sharepointContext) 
        {
            _sharepointContext = sharepointContext;
        }
    }

Note: Also, we can create our custom instance class of SharepointDataContext class to only make use of the services that we need and limit the access to services in our Sharepoint site.

SharePoint http data connector services

In this section we will explain and show some examples of the use of this library.

Remember
You will see that our library, some functions require a ServerRelativeUrl, it is not more than the path or route, of our folder or file. Here are some examples.

  • my-folder/graduation
  • my-folder/photos

If we don't set a value in the attribute ServerRelativeUrl of the library configuration when we do an instance of it, it will take the default base address instead a custom relative path, this can help us if we only want to have an interaction with only one library documents in SharePoint.

    // Returns a true or false if the folder exists or not.
    bool response = await _sharepointContext.ExistsFolderAsync("my-folder/graduation");

    // Returns a true or false if the file exists or not.
    bool response = await _sharepointContext.ExistsFileAsync("my-folder/graduation", "graduationFile.pdf");

    // Returns a record type Sharepoint Recycle Resource by a unique identifier.
    var response = await _sharepointContext.GetRecycleBinResourceByIdAsync(new Guid("00000000-0000-0000-0000-000000000000"));

    // Returns the file content of a document in SharePoint.
    byte[]? response = await _sharepointContext.DownloadFileAsync("my-folder/graduation", "graduationFile.pdf");
    
    // Returns true or false if the resource was deleted or not (Support file name in relative url).
    bool response = await _sharepointContext.DeleteResourceAsync("my-folder/graduation");
    bool response = await _sharepointContext.DeleteResourceAsync("my-folder/graduation/graduationFile.pdf");

    // Returns true or false if a file was deleted or not.
    bool response = await _sharepointContext.DeleteFileAsync("my-folder/graduation", "graduationFile.pdf");

    // Returns a record type Sharepoint Folder when it's created.
    // The difference between these two functions is that the first one, create a folder in the main server relative
    // url that was defined in the Configuration of the library, the second one, let us create a folder in a specific route. 
    var response = await _sharepointContext.CreateFolderAsync("my-new-Folder");
    var response = await _sharepointContext.CreateFolderAsync("my-folder/graduation", "my-new-folder");
    
    // Retuns a record type Sharepoint File when one is uploaded.
    var response = await _sharepointContext.UploadFileAsync("my-folder/graduation", "graduationPhoto.jpg", byte[] content);

    // Returns an unique identifier when a you want to move a resource to the Recycle bin (Support file name in relative url).
    var recordId = await _sharepointContext.DeleteResourceToRecycleBinByIdAsync("my-folder/graduation/graduationPhoto.jpg");

    // Returns true or false if the resource was restored correctly from Recycle bin.
    bool response = await _sharepointContext.RestoreRecycleBinResourceByIdAsync(new Guid("00000000-0000-0000-0000-000000000000"));

For future updates in the library, we plan to cover many other functions that can be useful in our interaction with a SharePoint Site.

Repository

Authors

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 921 7/22/2022 1.0.2 is deprecated.
1.0.1 534 7/22/2022
1.0.0 546 7/20/2022