AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. Content management
  3. SharePoint

SharePoint


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Creating a SharePoint connection
  • Updating a SharePoint connection
  • Deleting a SharePoint connection
  • Retrieving SharePoint lists
  • Retrieving SharePoint list items
  • Retrieving a file from a SharePoint server

Creating a SharePoint connection

C#
// Specifies the parameters for the SharePoint connection
// The siteUrl variable represents the URL of your configured SharePoint site
string siteUrl = "https://mycompany.sharepoint.com";
string userName = "yourSharePointUsername";
string password = "yourSharePointPassword";

// Creates a new SharePoint connection object
SharePointConnectionInfo newConnection = new SharePointConnectionInfo();

// Sets the properties of the connection
newConnection.SharePointConnectionSiteUrl = siteUrl;
newConnection.SharePointConnectionSiteID = SiteContext.CurrentSiteID;
newConnection.SharePointConnectionDisplayName = "New connection";
newConnection.SharePointConnectionName = "NewConnection";
newConnection.SharePointConnectionUserName = userName;
newConnection.SharePointConnectionPassword = password;

// Saves the SharePoint connection to the database
SharePointConnectionInfoProvider.SetSharePointConnectionInfo(newConnection);
> Back to list of examples

Updating a SharePoint connection

C#
// Gets the SharePoint connection
SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("NewConnection", SiteContext.CurrentSiteID);

// Updates the properties of the connection
connection.SharePointConnectionDisplayName = connection.SharePointConnectionDisplayName.ToLowerCSafe();

// Saves the updated connection to the database
SharePointConnectionInfoProvider.SetSharePointConnectionInfo(connection);
> Back to list of examples

Deleting a SharePoint connection

C#
// Gets the SharePoint connection
SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("NewConnection", SiteContext.CurrentSiteID);

if (connection != null)
{
    // Deletes the SharePoint connection
    SharePointConnectionInfoProvider.DeleteSharePointConnectionInfo(connection);
}
> Back to list of examples

Retrieving SharePoint lists

C#
// Gets the SharePoint connection
SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("NewConnection", SiteContext.CurrentSiteID);

// Converts the SharePointConnectionInfo into a connection data object
SharePointConnectionData connectionData = connection.ToSharePointConnectionData();

// Gets the list service implementation
ISharePointListService listService = SharePointServices.GetService<ISharePointListService>(connectionData);

// Chooses the SharePoint list type that will be retrieved
// You can use an enumeration or template identifier (listed in http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx)
int listType = SharePointListType.ALL;

try
{
    // Gets all lists of the specified type (all list types are retrieved in this case)
    DataSet results = listService.GetLists(listType);

    if ((results.Tables.Count == 0) || (results.Tables[0].Rows.Count == 0))
    {
        // No lists were retrieved from the SharePoint server
    }
}
catch (Exception ex)
{
    // The retrieval of the lists ended with an exception
    // Logs the exception to the Xperience event log
    Service.Resolve<IEventLogService>().LogException("SharePoint API Example", "EXCEPTION", ex);
}
> Back to list of examples

Retrieving SharePoint list items

C#
// Specifies the list name
string listName = "SharePointList";

// Gets the SharePoint connection
SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("NewConnection", SiteContext.CurrentSiteID);

// Converts the SharePointConnectionInfo into a connection data object
SharePointConnectionData connectionData = connection.ToSharePointConnectionData();

// Gets the list service implementation
ISharePointListService listService = SharePointServices.GetService<ISharePointListService>(connectionData);

try
{
    // Gets the specified list's items
    DataSet results = listService.GetListItems(listName);

    if ((results.Tables.Count == 0) || (results.Tables[0].Rows.Count == 0))
    {
        // No list items were retrieved from the SharePoint server 
    }
}
catch (Exception ex)
{
    // The retrieval of the list items ended with an exception
    // Logs the exception to the Xperience event log
    Service.Resolve<IEventLogService>().LogException("SharePoint API Example", "EXCEPTION", ex);
}
> Back to list of examples

Retrieving a file from a SharePoint server

C#
// Specifies the relative path of the file
string filePath = "/Picture library/picture.jpg";

// Gets the SharePoint connection
SharePointConnectionInfo connection = SharePointConnectionInfoProvider.GetSharePointConnectionInfo("NewConnection", SiteContext.CurrentSiteID);

// Converts the SharePointConnectionInfo into a connection data object
SharePointConnectionData connectionData = connection.ToSharePointConnectionData();

// Gets the file service implementation
ISharePointFileService fileService = SharePointServices.GetService<ISharePointFileService>(connectionData);

// Gets the SharePoint URL provider
SharePointUrlProvider sharePointUrlProvider = new SharePointUrlProvider(connection.SharePointConnectionName);

try
{
    // Gets the file object
    ISharePointFile file = fileService.GetFile(filePath);

    // Gets the file's metadata
    string extension = file.Extension;

    // Gets a stream of the file's binary content
    Stream fileContentStream = file.GetContentStream();

    // Gets a byte array of the file's binary content
    byte[] fileContentBytes = file.GetContentBytes();

    // Gets the URL of the file
    string fileUrl = sharePointUrlProvider.GetSharePointFileUrl(file.ServerRelativeUrl);
}
catch (Exception ex)
{
    // The retrieval of the file ended with an exception
    // Logs the exception to the Xperience event log
    Service.Resolve<IEventLogService>().LogException("SharePoint API Example", "EXCEPTION", ex);
}
> Back to list of examples