Self-hosted apps run isolated from SharePoint site. The code that worked with SharePoint 2010 web parts, the code that read or write data from the SharePoint site doesn't work in self-hosted apps.
Don't be scared, it is a minor change, it is going to sting a little, not much.
The difference is in access to context. You have to use TokenHelper.cs to access SharePoint lists from a self-hosted (provider hosted) app.
Here is code for accessing context with CSOM:
context clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
The rest of the code is something that works in SharePoint 2010 web part. Here is an example of how to add a list item with CSOM:
context clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
Web web = context.Web;
ListCollection lists = web.Lists;
List list = lists.GetById(listId);
context.Load<ListCollection>(lists);
context.Load<List>(list);
ListItemCreationInformation listItemCreationInfo = new ListItemCreationInformation();
var newItem = list.AddItem(listItemCreationInfo);
newItem["Title"] = "New item title";
newItem.Update();
context.ExecuteQuery();
Related Content
SharePoint 2013 Provider App hosted on Office 365
SharePoint 2013 JavaScript - Office Store App Licensing
SharePoint 2103 JavaScript - Add List with Columns
SharePoint JavaScript Client Object Model - why not
Geolocation
SharePoint 2013 Apps
Other Things I Wrote
Design Manager
Channels in SharePoint 2013
Social
Content Search and Metadata Driven Navigation
SharePoint 2013 Mobile
SharePoint 2013 SkyDrive
SharePoint 2013 MySite
Don't be scared, it is a minor change, it is going to sting a little, not much.
The difference is in access to context. You have to use TokenHelper.cs to access SharePoint lists from a self-hosted (provider hosted) app.
Here is code for accessing context with CSOM:
context clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
The rest of the code is something that works in SharePoint 2010 web part. Here is an example of how to add a list item with CSOM:
context clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
Web web = context.Web;
ListCollection lists = web.Lists;
List list = lists.GetById(listId);
context.Load<ListCollection>(lists);
context.Load<List>(list);
ListItemCreationInformation listItemCreationInfo = new ListItemCreationInformation();
var newItem = list.AddItem(listItemCreationInfo);
newItem["Title"] = "New item title";
newItem.Update();
context.ExecuteQuery();
Related Content
SharePoint 2013 Provider App hosted on Office 365
SharePoint 2013 JavaScript - Office Store App Licensing
SharePoint 2103 JavaScript - Add List with Columns
SharePoint JavaScript Client Object Model - why not
Geolocation
SharePoint 2013 Apps
Other Things I Wrote
Design Manager
Channels in SharePoint 2013
Social
Content Search and Metadata Driven Navigation
SharePoint 2013 Mobile
SharePoint 2013 SkyDrive
SharePoint 2013 MySite