This is the first in a short series about how to use C# to perform simple Create, Read, Update and Delete (CRUD) operations on a SharePoint list.
SharePoint CRUD: Part 1 – How to view list metadata
When working with SharePoint lists, you’ll need to reference the column names used in the list and sometimes those column names aren’t exactly what you think they should be. For example, if a column name has a space in it, SharePoint will add a string of characters to replace that space in the column name. “User Name” would result in the column name of “User_x0020_Name”.
Don’t worry, SharePoint has an easy way to view these column name values using SharePoint’s REST API. Using the following URL, you can view an XML version of the list items:
The [SERVER], [SITE] and [LISTNAME] should be replaced with your own values. The following site has a nice list of SharePoint REST API URLS:
If you’re using Internet Explorer, you will most likely see the following screen when opening the URL above:
If you see the above screen, you’ll need to disable Feed Reading View in the settings. To do this, follow these instructions:
- Open Internet Explorer.
- Click the ALT key to display the top menu if it is not already showing.
- Click TOOLS.
- Select the INTERNET OPTIONS.
- Click the CONTENT tab.
- Click on the SETTINGS button.
- Uncheck the “Turn on feed reading view” checkbox.
- Click OK.
- Click OK.
- If the page still shows the same after a refresh, close all instances of the browser and reopen Internet Explorer and try the URL again.
Now, you should be able to view the list item data as XML. You should see a tag called <d:EntityPropertyName> for each column in the list. NOTE: SharePoint creates many columns that are used in the background. These will also show in the XML data.
- Create a library that wraps the SharePoint CRUD functionality
- Use AutoMapper to map SharePoint list items to C# objects
- Create a DataContext that uses the library and simulates basic Entity Framework functionality