Giter Club home page Giter Club logo

sharepoint-add-in-rest-odata-basicdataoperations's Introduction

page_type products languages urlFragment description extensions
sample
office-sp
office-365
csharp
crud-operations-sharepoint
Use the SharePoint REST/OData endpoints to perform operations on lists and list items from a SharePoint Add-in.
contentType technologies createdDate
samples
Add-ins
8/8/2015 11:33:40 AM

Basic CRUD operations in SharePoint Add-ins using the REST/OData 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 REST/OData endpoints 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 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 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 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

  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 add-in 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 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.

Additional resources

Get to know the SharePoint 2013 REST service.

Open Data Protocol

OData: JavaScript Object Notation (JSON) Format

OData: AtomPub Format.

Copyright

Copyright (c) Microsoft. All rights reserved.

sharepoint-add-in-rest-odata-basicdataoperations's People

Contributors

lauragra avatar rick-kirkham avatar supernova-eng avatar vesajuvonen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharepoint-add-in-rest-odata-basicdataoperations's Issues

Add Item to List returning 400: Bad Request

Line 302, Default.aspx.cs file.

There is a extra closing bracket that is making the JSON body malformed, producing a 400 Bad Request response when trying to Add an Item to a List.

Fixed with just removing it like this:

 //Execute a REST request to add an item to the list.
string itemPostBody = "{'__metadata':{'type':'" + entityTypeName + "'}, 
                                      'Title':'" + newItemName + "'}";
Byte[] itemPostData = System.Text.Encoding.ASCII.GetBytes(itemPostBody);

SPRemoteEventProperties could not be found

Probably something stupid on my part but tried to add reference to Microsoft.SharePoint.Client.EventReceivers and that isn't found. Checked documentation for that namespace and I don't see that it was depreciated.

Name of Project too long?

I was unable to build the project because the name was too long. Renaming the projects and solution file didn't seem to help either.

Newbie to SharePoint Online Add-Ins - Advice on Deploying an Add-In

Hello,

I am fairly new to deploying add-in's to the SharePoint Online environment. I'm currently trying to install the BrandingAlternateCSSUrl sample code on our SharePoint Online environment, but I'm running into a sideloading of apps issue. I realize I'm working on a SPO website that is NOT a development website and I wanted to know what my options were to publish the add-in to the organization's add-in catalog. I'm using Visual Studio 2013 and the SharePoint Online environment - a publishing website. I'm happy to provide more details as needed, however, I would appreciate any start as to how-to release an add-in.

Thanks.

Communication with the Sharepoint server is canceled

Hey Guys,
I'm looking into creating a pretty simple display feature on our .NET intranet that fetches links to Sharepoint files in a specific folder in a list on our Office365 Sharepoint.

I have fetched your Sample packagem followed the steps and changed the Site URL, have the Add-in authenticate myself against my Sharepoint installation, but when I run the Add-in project (Not the web project) I get an error stating "Sideloadning of apps is not enabled on this site". I'm not a Sharepoint expert, but have some Admin experience, when googling the error I get that it's not adviseable to allow on production? (We're just a small company that use Sharepoint Online for document management and we don't have any development environment for Sharepoint related features as this is our first integration).

How do I enable that on Sharepoint (if at all) in order to do this or what could I be missing/doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.