/SharePoint-Add-in-CSOM-BasicDataOperations

Use the SharePoint client-side object model (CSOM) to perform create, read, update, and delete operations on lists and list items from a SharePoint Add-in.

Primary LanguageC#MIT LicenseMIT

page_type products languages extensions description
sample
office-sp
office-365
csharp
contentType technologies createdDate
samples
Add-ins
8/17/2015 1:40:30 PM
Use the SharePoint client-side object model to perform create, read, update, and delete operations on lists and list items from a SharePoint Add-in.

Basic CRUD operations in SharePoint Add-ins using the client-side object model (CSOM) APIs

SharePoint add-in model is considered as a legacy option for extending SharePoint user interface. Please see SharePoint Framework documentation and the SharePoint Framework samples for the future proven option to extend SharePoint Online. Possible backend services should be using Azure Active Directly based registration and related app models.

Summary

Use the SharePoint client-side object model (CSOM) to perform create, read, update, and delete operations on lists and list items from a SharePoint Add-in.

Applies to

  • SharePoint Online and on-premise SharePoint 2013 and later

Prerequisites

This sample requires the following:

Description of the code

The code that uses the CSOM APIs is located in the Default.aspx.cs file of the SharePoint-Add-in-CSOM-BasicDataOperationsWeb project. The Default.aspx page of the add-in appears after you install and launch the add-in and looks similar to the following.

The add-in start page with a table listing all the list on the site by name and ID.

The sample demonstrates the following:

  • How to read and write data to and from the host web of a SharePoint Add-in.

  • How to load the data returned from SharePoint into the client context object and then display the data.

To use the sample

  1. Open Visual Studio as an administrator.
  2. Open the .sln file.
  3. In Solution Explorer, highlight the SharePoint add-in project and replace the Site URL property with the URL of your SharePoint developer site.
  4. Press F5.
  5. After the app installs, the consent page opens. Click Trust It.
  6. Enter a string in the text box beside the Add List button and click the button. In a moment, the page refreshes and the new list is in the table.
  7. Click the ID of the list, and then click Retrieve List Items. There will initially be no items on the list. Some additional buttons will appear.
  8. Add a string to the text box beside the Add Item button and press the button. The new item will appear in the table in the row for the list.
  9. Add a string to the text box beside the Change List Title button and press the button. The title will change in the table.
  10. Press the Delete the List button and the list is deleted.

Do not delete any of the built-in SharePoint lists. If you mistakenly do so, recover the list from the SharePoint Recycle Bin.

Troubleshooting

Problem Solution
Visual Studio does not open the browser after you press the F5 key. Set the app for SharePoint project as the startup project.
HTTP error 405 Method not allowed. Locate the applicationhost.config file in %userprofile%\Documents\IISExpress\config.

Locate the handler entry for StaticFile, and add the verbs GET, HEAD, POST, DEBUG, and TRACE.

Questions and comments

We'd love to get your feedback on this sample. You can send your questions and suggestions to us in the Issues section of this repository.

Additional resources

SharePoint Add-ins

Complete basic operations using SharePoint 2013 client library code

Copyright

Copyright (c) Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.