Displaying SharePoint data on the live site

If you have data stored on a SharePoint Online server, Xperience enables you to retrieve this data and include it on your live site – you can display images and provide download links for files.

After you configure a SharePoint integration connection, you can display SharePoint data using the API within the CMS.SharePoint namespace:

  1. In Visual Studio, open your project and navigate to where you want to display the data.

  2. In the code, get an instance of a SharePoint service using a configured SharePoint integration connection.

     using System.Data;
     using CMS.SharePoint;
     // Use the code name of your SharePoint connection and the code name of your site
     SharePointConnectionInfo connectionInfo = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("ConnectionCodename", "SiteName");
     ISharePointListService service = SharePointServices.GetService<ISharePointListService>(connectionInfo.ToSharePointConnectionData());
  3. Retrieve a set of SharePoint data. To obtain the name of a SharePoint library, open your SharePoint server, go to the Site Contents tab and use the library name as specified in the Name column. Do not use the code name of a library from the SharePoint application in the Xperience administration interface.

     DataSet images = service.GetListItems("SharePointLibraryName");
  4. Iterate through the data and retrieve URLs from the FileRef row using the GetSharePointFileUrl method.

     SharePointUrlProvider sharePointUrlProvider = new SharePointUrlProvider(connectionInfo.SharePointConnectionName);
     foreach (DataRow row in images.Tables[0].Rows)
         // Retrieves the URL of a piece of data, which you can now process, e.g. by passing it to a model
         string fileUrl = sharePointUrlProvider.GetSharePointFileUrl(row["FileRef"].ToString());
         // You can also access other available metadata
         string fileTitle = row["Title"].ToString()
  5. Use the retrieved URLs to display the content on your website (for example, use a model class to pass the URLs to a view).

If you want to see a sample implementation of a SharePoint integration, visit Example - Displaying a SharePoint picture library.