---
title: SharePoint integration examples
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

This page demonstrates how you can use the SharePoint integration in Kentico:

- [SharePoint integration examples](#site-hierarchy) - learn how to display site lists.
- [SharePoint integration examples](#list-items) - learn how to display items from a list.
- [SharePoint integration examples](#picture-libraries) - learn how to retrieve picture library type lists.
- [SharePoint integration examples](#list-of-pictures) - learn how to display pictures from picture libraries.

## Site hierarchy

Here you will learn how you can display site lists resembling the site hierarchy panel on a SharePoint site.

![A site list resembling the site hierarchy panel on a SharePoint site](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/111.png "A site list resembling the site hierarchy panel on a SharePoint site")

[Add](https://docs.kentico.com/k8/developing-websites/developing-websites-using-the-portal-engine/using-and-configuring-web-parts.md) one of the SharePoint web parts (e.g. **SharePoint repeater**) onto a page and configure the web part in the following way:

- **SharePoint site URL** - enter the URL of your SharePoint server.
- **Username** and **Password** - enter your username and password or leave the fields empty if you configured them in _Settings -> Integration -> Microsoft SharePoint_.
- **Mode**: _Display site lists_
- **Transformation** - the system offers a transformation for displaying site hierarchy called _SiteHierarchy_ under the _SharePoint - Transformation&#x73;_&#x64;ocument type. You need to edit the transformation and change the name of the SharePoint server in the code.

Leave the default values for the remaining properties and click **OK**. The system creates a link to each of the lists on the SharePoint server.

![Site hierarchy - links to lists on a SharePoint server](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/00.png "Site hierarchy - links to lists on a SharePoint server")

## List items

Using the _Display list items_ mode, you can display items from any list from the SharePoint server.

The example uses a custom list named _Customers_ in SharePoint. The list stores information about company customers in fields such as _Customer name_, _Street_, _City_, _Phone_, etc. You want to display data from this list on your Kentico website.

![Displaying items from a custom list in SharePoint](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/33.png "Displaying items from a custom list in SharePoint")

[Add](https://docs.kentico.com/k8/developing-websites/developing-websites-using-the-portal-engine/using-and-configuring-web-parts.md) one of the SharePoint web parts (e.g. **SharePoint repeater**) onto a page:

1. Configure the web part in the following way:

- **SharePoint site URL** - enter the URL of your SharePoint server.
- **Username** and  **Password** - enter your username and password or leave the fields empty if you configured them in _Settings -> Integration -> Microsoft SharePoint._
- **Mode**: _Display list items_
- **Transformation** - the system offers a transformation for displaying item lists called _ListItems_ under the _SharePoint - Transformations_ document type. You need to change the name of the SharePoint server in the transformation code.
- **Show raw response**: enabled; this is because we will need to inspect the retrieved data and change the transformation to suit our needs.

Leave the default values for the remaining properties and click **OK**. You should see a result similar to the screenshot below.

![](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/22.png)

To see the customers' name and city, you need to look into the raw output and search for those fields. You can find them there under the _ows\_CustomerName_ and _ows\_Street_ attributes.

2. Now that you know the names of the attributes, you need to edit the transformation code or create a new transformation.

Replace the original **Transformation**:

```html

<%# Eval("ows_Title") %> (<%#  Eval("ows_Created")%>) <br />

```

with something like this:

```html

<%# Eval("ows_CustomerName") %> - <%#  Eval("ows_City")%> <br />

```

The output now displays the desired values.

![](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/11.png)

3. To click individual items and see more details, you must prepare the **Selected item transformation**. The transformation may look like the following code sample:

```xml

<strong><%# Eval("ows_CustomerName") %></strong><br/>
<%# Eval("ows_City")%> <br/>
<%# Eval("ows_Street")%> <br/>
<%# Eval("ows_Phone")%> <br/> 

```

4. In the web part's properties, you must enter the name of the field by which you want to select items. In this case, it is the _ID_ field. In the raw response output, you can see it as _ows\_ID_. Enter the following values:

- **Selected item querystring key name**: _id_
- **Selected item field name**: _ID_
- **Selected item field type**: _Counter_

Finally, you must alter the original **Transformation** to suit the values you have just entered. This means you need to create a link to customer details using the _id_ parameter in the query string. It can look like this:

```xml

<a href="<%# CMS.Helpers.URLHelper.AddParameterToUrl(CMS.Helpers.RequestContext.RawURL, "id", (string)Eval("ows_ID")) %>">
<%# Eval("ows_CustomerName") %> - <%# Eval("ows_City")%> </a><br />

```

The final result, a simple text list of customers with links, looks like this:

![](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/6.png)

After clicking a customer name, the system displays customer details.

![](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/5.png)

5. Now configure the **Advanced** settings. You want that the system displays a maximum of 10 customers. Besides, the displayed customers are from _Queens_ only.

Enter number 10 into the **Row limit** field and use this code as the **Query**:

```csharp

<Query>
<Where><Eq><FieldRef Name="City" /><Value Type="Text">Queens</Value></Eq></Where> 
</Query>

```

The __ tag means equals, the field name is _City_, and its value of type _Text_ equals to _Queens_.

Click **OK**. Now you should see the filtered output as in the following screenshot:

![](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/4.png)

## Picture libraries

Here you will learn how you can use SharePoint to retrieve only a picture library type list. To achieve this, you need to configure the following properties:

- **SharePoint site URL** - enter the URL of your SharePoint server.
- **Username** and **Password** - enter your username and password or leave the fields empty if you configured them in _Settings -> Integration -> Microsoft SharePoint_.
- **Mode**: _Display picture libraries_
- **Transformation** - the system offers a transformation for displaying picture libraries called _PictureLibLists_ under the _SharePoint - Transformations_ document type. You need to change the name of the SharePoint server in the transformation code.

Leave the default values for the remaining properties and click **OK**. You should see a result similar to the screenshot below. The system displays a list of picture libraries with links to the SharePoint server.

![A list of picture libraries with links to a SharePoint server](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/3.png "A list of picture libraries with links to a SharePoint server")

## List of pictures

The _Display list of pictures_ mode allows you to display pictures from picture libraries on a SharePoint server.

![Displaying pictures from picture libraries on a SharePoint server](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/2.png "Displaying pictures from picture libraries on a SharePoint server")

This example uses a picture library named _Images_ on the SharePoint server. To display the pictures on your Kentico website, you must enter the following properties of a suitable web part (for example, the **SharePoint repeater** web part):

- **SharePoint site URL** - enter the URL of your SharePoint server.
- **Username** and **Password** - enter your username and password or leave the fields empty if you configured them in _Settings -> Integration -> Microsoft SharePoint_.
- **Mode**: _Display list of pictures_
- **List name**\*: Images\*
- **Transformation** - the system offers a transformation for displaying picture lists called _Pictures_ under the _SharePoint - Transformation&#x73;_&#x64;ocument type. For correct behavior, you must only change the name of the SharePoint server.

Leave the default values for the remaining properties and click **OK**. You should see a result similar to the screenshot below.

![Displaying pictures from the SharePoint server on a Kentico site](https://docs.kentico.com/docsassets/k8/sharepoint-integration-examples/1.png "Displaying pictures from the SharePoint server on a Kentico site")

The transformation code looks like this:

```html

<%# SharePointFunctions.SplitSharePointField((string)Eval("ows_FileLeafRef"),1) %><br/>
<img src="<%# SharePointFunctions.GetSharePointFileUrl("tester4", SharePointFunctions.SplitSharePointField((string)Eval("ows_FileRef"),1)) %>&maxsidesize=200" /> <br />

```

The system downloads the images through the **GetSharePointFile.aspx** page, same as documents. So you need to create in the transformation __ tags with _src_ attributes pointing to this page. For ease of use, there is the **GetSharePointFileUrl** function in the **SharePointFunctions** class, which takes two parameters and returns the URL which downloads the file. The first parameter is the server name (or site url), the second one is the location of the file in SharePoint. The final URL looks like this:

- _\~/CMSModules/Sharepoint/CMSPages/GetSharePointFile.aspx?server=server\_name\&name=Images/Sunset.jpg_

> **Note:** The credentials from the settings are always used for downloading the file when the **GetSharePointFile** page is used.

There is another useful function in the **SharePointFunctions** class called **SplitSharePointField**. SharePoint, for some reason, creates combined attribute values for certain fields. It looks like this: _ows\_FileLeafRef="2;#Blue hills.jpg"_.

You often need to use only a part of such a value. The **SplitSharePointField** function serves the purpose. The first argument is a combined value and the second one is the index of the part you want to have in the output.

### The GetSharePointFile.aspx page

The **GetSharePointFile.aspx** page is a special page located under the **\~/CMSModules/Sharepoint/CMSPages** directory. The correct URL to access the page is:

- _\~/ CMSModules/Sharepoint/CMSPages/GetSharePointFile.aspx?server=server\_name\&name=Images/Sunset.jpg_

The page downloads a specified file from the SharePoint server and sends it further to the user. The credentials that you configured in **Settings -> Integration -> Microsoft SharePoint** are used for authentication by the web service. You can control the Content-Disposition HTTP header using the _disposition_ query parameter.

#### Images

The page supports _maxsidesize_, _width_ and _height_ parameters to control the size of the image, and the Kentico cache is used. You can configure the [cache](https://docs.kentico.com/k8/configuring-kentico/optimizing-website-performance/configuring-caching/caching-files-and-resources.md) in **Settings -> System -> Performance**: **Cache files (minutes)**, **Client cache (minutes)**.

#### Servers

You can specify servers that the system can retrieve the files from. Enter names of the servers, separated by semicolons, into the **Allowed servers** setting in **Settings -> Integration -> Microsoft SharePoint**.

> **Warning:** Because the settings configured in **Settings -> Integration -> Microsoft SharePoint** are automatically used for authentication by the **GetSharePointFile.aspx** page and since the URL to access the page can be entered manually, it is highly recommended to enter the credentials of a user that is authorized to access only the files you want to display on your website.
