Basic CRUD operations in Project Add-ins using the REST APIs
Use the Project REST endpoints to perform create, read, update, and delete operations onprojects from a Project Add-in.
- Project Online and on-premise Project 2013 and later
As a Project/Program/Portfolio portfolio manager, I would like to use an app that displays the projects and allows me create, update and delete projects.
- Update the PWA site in the Project-Add-in-REST-OData-BasicDataOperations Project
- Update the login/password to your PWA site.
- Run the app
To use this code sample, you need the following:
- PWA Site (Project Online, Project Server 2013 or Project Server 2016)
- Visual Studio 2013 or later
How the sample affects your tenant data
This sample runs CSOM methods that create, edit the project name and delete projects in the PWA instance for the specified user.
Copyright (c) 2016 Microsoft. All rights reserved.
This sample requires the following:
A SharePoint 2013 (or later) development environment that is configured for add-in isolation and OAuth. (A SharePoint Online Developer Site is automatically configured. For an on premise development environment, see Set up an on-premises development environment for SharePoint Add-ins and Use an Office 365 SharePoint site to authorize provider-hosted add-ins on an on-premises SharePoint site.)
Visual Studio and the Office Developer Tools for Visual Studio installed on your developer computer
Basic familiarity with RESTful web services and OData
Description of the code
The code that uses the REST APIs is located in the Default.aspx.cs file of the SharePoint-Add-in-REST-OData-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 sample demonstrates the following:
How to read and write data to and from a SharePoint host web. This data conforms with the OData protocol to the REST endpoints where the list and list item entities are exposed.
How to parse Atom-formatted XML returned from these endpoints and how to construct JSON-formatted representations of the list and list item entities so that you can perform Create and Update operations on them.
Best practices for retrieving form digest and eTag values that are required for Create and Update operations on lists and list items.
To use the sample
- Open Visual Studio as an administrator.
- Open the .sln file.
- In Solution Explorer, highlight the SharePoint add-in project and replace the Site URL property with the URL of your SharePoint developer site.
- Press F5.
- After the add-in installs, the consent page opens. Click Trust It.
- 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.
- 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.
- 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.
- Add a string to the text box beside the Change List Title button and press the button. The title will change in the table.
- 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.
|Visual Studio does not open the browser after you press the F5 key.||Set the SharePoint Add-in 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.
Copyright (c) Microsoft. All rights reserved.