Connect to SharePoint Data from Blazor Apps



Build ASP.NET Core Blazor C# apps that integrate with real-time SharePoint data using standard SQL.

Blazor is a framework for developing modern, client-side web UIs using .NET technology. Instead of coding in JavaScript, developers can use the familiar C# language and .NET libraries to build app UIs.

The CData ADO.NET Provider for SharePoint can be used with standard ADO.NET interfaces, such as LINQ and Entity Framework, to interact with live SharePoint data. Since Blazor supports .NET Core, developers can use CData ADO.NET Providers in Blazor apps. In this article, we will guide you to build a simple Blazor app that talks to SharePoint using standard SQL queries.

About SharePoint Data Integration

Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:

  • Access data from a wide range of SharePoint versions, including Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007 and above, and SharePoint Online.
  • Access all of SharePoint thanks to support for Hidden and Lookup columns.
  • Recursively scan folders to create a relational model of all SharePoint data.
  • Use SQL stored procedures to upload and download documents and attachments.

Most customers rely on CData solutions to integrate SharePoint data into their database or data warehouse, while others integrate their SharePoint data with preferred data tools, like Power BI, Tableau, or Excel.

For more information on how customers are solving problems with CData's SharePoint solutions, refer to our blog: Drivers in Focus: Collaboration Tools.


Getting Started


Install the CData ADO.NET Provider for SharePoint

CData ADO.NET Providers allow users to access SharePoint just like they would access SQL Server, using simple SQL queries.

Install the SharePoint ADO.NET Data Provider from the CData website or from NuGet. Search NuGet for "SharePoint ADO.NET Data Provider."

Create a SharePoint-Connected Blazor App

Start by creating a Blazor project that references the CData ADO.NET Provider for SharePoint

  1. Create a Blazor project on Visual Studio.
  2. From the Solution Explorer, right click Dependencies, then click Add Project Reference.
  3. In the Reference Manager, click the Browse button, and choose the .dll file of the installed ADO.NET Provider (e.g. System.Data.CData.SharePoint.dll, typically located at C:\Program Files\CData\CData ADO.NET Provider for SharePoint\lib etstandard2.0).

SELECT SharePoint Data from the Blazor App

  1. Open the Index.razor file from the Project page.
  2. In a SharePointConnection object, set the connection string:

    Set the URL property to the base SharePoint site or to a sub-site. This allows you to query any lists and other SharePoint entities defined for the site or sub-site.

    The User and Password properties, under the Authentication section, must be set to valid SharePoint user credentials when using SharePoint On-Premise.

    If you are connecting to SharePoint Online, set the SharePointEdition to SHAREPOINTONLINE along with the User and Password connection string properties. For more details on connecting to SharePoint Online, see the "Getting Started" chapter of the help documentation

    For example: User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;

  3. The code below creates a simple Blazor app for displaying SharePoint data, using standard SQL to query SharePoint just like SQL Server.

          @page "/"
          @using System.Data;
          @using System.Data.CData.SharePoint;
          
          <h1>Hello, world!</h1>
          
          Welcome to your Data app.
          
          <div class="row">
              <div class="col-12">
          
                  @using (SharePointConnection connection = new SharePointConnection(
                    "User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;"))
                  {
                      var sql = "SELECT Name, Revenue FROM MyCustomList";
                      var results = new DataTable();
          
                      SharePointDataAdapter dataAdapter = new SharePointDataAdapter(sql, connection);
                      dataAdapter.Fill(results);
          
                      <table class="table table-bordered">
                          <thead class="thead-light">
                              <tr>
                                  @foreach (DataColumn item in results.Rows[0].Table.Columns)
                                  {
                                      <th scope="col">@item.ColumnName</th>
                                  }
                              </tr>
                          </thead>
                          <tbody>
                              @foreach (DataRow row in results.Rows)
                              {
                                  <tr>
                                      @foreach (var column in row.ItemArray)
                                      {
                                          <td>@column.ToString()</td>
                                      }
                                  </tr>
                              }
                          </tbody>
                      </table>
                  }
              </div>
          </div>
        
  4. Rebuild and run the project. The ADO.NET Provider renders SharePoint data as an HTML table in the Blazor app.

    At this point, you have a SharePoint-connected Blazor app, capable of working with live SharePoint data just like you would work with a SQL Server instance. Download a free, 30-day trial and start working with live SharePoint data in your Blazor apps today.

Ready to get started?

Download a free trial of the SharePoint Data Provider to get started:

 Download Now

Learn more:

SharePoint Icon SharePoint ADO.NET Provider

Provides .NET developers with the power to easily connect their Web, Desktop, and Mobile applications to data in SharePoint Server Lists, Contacts, Calendar, Links, Tasks, and more!