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:
In Visual Studio, open your project and navigate to where you want to display the data.
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());
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");
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() }
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.