APPLICATION INTEGRATION OPTIONS IN SHAREPOINT 2013

The new application model in SharePoint 2013 offers a number of options for your application to deeply integrate with SharePoint, other systems, and data. These options fall into the following categories:

  • User interface integration
  • Events and logic integration
  • Data integration

When you think about building a solution, you must evaluate your options for how you want to surface your application inside SharePoint (UI), how you want to call code and process actions when a user uses your application (events and logic), and how and where you store and work with your application’s data and data that resides in other systems (data). Understanding what options are available and how they work is critical when designing your application.

The following sections cover some of the most common options you have for each of the layers (UI, events, and data) in the new SharePoint application model.

User Interface Integration

Three main integration points are available to you in the SharePoint user interface as part of the SharePoint application model:

  • App Parts and Pages
  • Ribbon and Action menus
  • Navigation

App Parts and Pages offer you the ability to surface your applications’ user interface to your users. For people familiar with SharePoint 2010, App Parts are similar to Web Parts. Navigation lets users find your application, and integrating with the Ribbon and Action menus lets your users take actions in the same familiar location that they do elsewhere in SharePoint. Using one or more of these building blocks enables you to integrate your application’s user interface with that of SharePoint’s and expose your app to its users.

App Parts and Pages

App Parts are reusable and configurable windows into your application. They are analogous to Web Parts in SharePoint 2010; however, the UI is generated and served remotely within your application as opposed to being generated from code running in the SharePoint process. Typically, the interface is rendered from another environment such as Windows Azure in the cloud or IIS on premises. Additionally, App Parts show in the Web Part gallery alongside all the other Web Parts in SharePoint, so they are easy to find and add to your SharePoint pages. Your solutions can consist of one or more App Parts, which should typically surface parts of your application that make sense to show alongside other Web Parts, such as a summary of data or a small set of controls. Figure 6-1 shows a weather App Part that has been added to the homepage of a site. It acts much like a Web Part would except that the UI of your application is embedded within the part via an iFrame. This means your application UI can be served from anywhere you choose, as long as it is accessible from the user’s browser. As you will see later in this section, part of an App Part’s configuration is the URL that the iFrame should be pointed at. Along with this URL you can feed additional parameters that your App’s logic can pick up from the query string. These can be properties set via the App Parts property panel, for example.


NOTE When designing your application try to think about how parts of your application and its data might be useful in other places, and use an App Part if appropriate.

Pages are much like an App Part except that they are viewed in a larger, fuller window style. Unlike with an App Part though, when someone launches your app’s page via a navigation link or similar method, the whole browser is directed to your app’s page thus giving your app full control over what is displayed. This ability enables you to include and show much more of your application to the user. Using Pages is good for when you need a lot of room to do things such as have the user fill in a large form or show a lot of data. Additionally, parameters can be passed along on the URL much like with an App Part. SharePoint provides a number of controls to assist you in branding your application so that it fits well with the look and feel of SharePoint. This includes a top navigation bar, as shown in Figure 6-2.


NOTE To maintain a consistent user experience in your solutions, App Parts and Pages in SharePoint 2013 allow you to include a “Chrome Control” that adds a top navigation bar and defines standard styles for your application. This helps you make your application UI look consistent with that of SharePoint’s.

To get a better feel for how App Parts and Pages work, try your hand at creating an app and adding these new elements to it. The following activity walks you through the process.


TRY IT OUT: Building Your First SharePoint Application (UserInterfaceIntegration.zip)
In this exercise you create a new SharePoint application, add an App Part to it, and deploy it to SharePoint Online. Prior to beginning this exercise you should have already signed up for and created your developer Office 365 SharePoint site. You can do that via the http://msdn.microsoft.com/sharepoint website.
1. Run Visual Studio 2012 as Administrator.
2. Select File ⇒ New ⇒ Project.
3. In the New Project dialog, expand Templates ⇒ Visual C# ⇒ Office/SharePoint ⇒ Apps.
4. Select App for SharePoint 2013 and enter the Name, MyFirstSharePointApp. Click OK.
5. In the Specify the App for SharePoint settings dialog, provide the URL to your Office 365 developer site and click the Validate button to confirm connectivity to the site.
6. For the question, “How do you want to host your app for SharePoint?” select Autohosted, and then click Finish.
7. Right-click the MyFirstSharePointApp project and select Add ⇒ New Item. In the Add New Item dialog select Client Web Part and name it MyAppPart. Click Add.
8. Open the Elements.xml under MyAppPart if it is not already open.
9. Replace the <Content Type="html" Src="" /> block with the following and save the file:
<Content Type="html" Src="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}" />
10. Open the Default.aspx page.
11. Replace everything after the line starting with <%@ Page with the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js" 
type="text/javascript"></script>
    <script type="text/javascript" 
src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>      
 
    <script type="text/javascript">
        var hostweburl;
 
        $(document).ready(function () {
            hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
            var scriptbase = hostweburl + "/_layouts/15/";
 
            var dclink = document.createElement("link");
            dclink.setAttribute("rel", "stylesheet");
            dclink.setAttribute("href", scriptbase + "defaultcss.ashx");
 
            var head = document.getElementsByTagName("head");
            head[0].appendChild(dclink);
        });
 
        function getQueryStringParameter(paramToRetrieve) {
            var params = document.URL.split("?")[1].split("&");
            var strParams = "";
            for (var i = 0; i < params.length; i = i + 1) {
                var singleParam = params[i].split("=");
                if (singleParam[0] == paramToRetrieve)
                    return singleParam[1];
            }
        }
    </script>
 
</head>
<body>
    <form id="form1" runat="server">
    <h1 class="ms-core-pageTitle">Your First SharePoint Application!</h1>
    <h1 class="ms-accentText">Put your app UI here.</h1>
    <div>
        <h2 class="ms-webpart-titleText">Use the SharePoint CSS</h2>
        <a class="ms-commandLink" href="#">links</a>
        <br />
        You can use the SharePoint CSS in your app by referencing it in your pages.
    </div>
    </form>
</body>
</html>
12. Press F5 to compile, package, deploy, and debug your application. When the process is complete, a browser launches to a page asking, “Do you trust MyFirstSharePointApp?” Click Trust It to continue. You should see your application listed, as shown in Figure 6-3:
13. Click on your app’s tile image to navigate to it. You might see a security certificate warning as shown in Figure 6-4. This is because your app isn’t correctly secured with SSL while running in your development environment. Click the Show content button to continue.
You should see your page render as shown in Figure 6-5. It is using the SharePoint style sheet.
14. Navigate back to your SharePoint site.
15. Navigate to your site’s homepage by clicking the Home link in the Quick Navigation on the left side of the page.
16. Click the Page ribbon and select Edit. You will now add your new App Part to your site’s homepage.
17. Click the Insert Ribbon tab and click the App Part button.
18. Select MyAppPart from the list of parts and click Add to add the part to your page.
19. Click Save in the ribbon when the operation completes.
You should now see your new App Part displayed on the page with both the name of your site displayed and “My application goes here!” as shown in Figure 6-6. Congratulations — you have just created a SharePoint application!
How It Works
In this exercise you first created a new project using one of the new project templates in Visual Studio 2012 for SharePoint application development. These templates provide the starting point for any new app, a project for packaging the declarative parts of your application that don’t include compiled code for installation into SharePoint, and a Web project for your app’s code for Provider-hosted and auto-hosted applications. When you run the solution, Visual Studio packages up these projects and deploys the app project package (.app file in the bin directory) to your SharePoint site’s application gallery. Alongside that process it runs your app’s code in a Web project on your local development IIS instance. Ultimately, after your Autohosted application is packaged for release that project will be packaged up for deployment into a location in Azure where it will run instead.
The App Part you created is simply an HTML <iframe> window into your application as specified by the src property on the Content node of your App Parts elements.xml file. However, it also adds some special tokens to the URL query string of that page to pass it additional information about who the caller is. This information is then used by the TokenHelper.GetClientContextWithContextToken helper function to assist in the construction of a CSOM client context that makes calls to SharePoint authenticated as that application and caller. This ensures your app’s code can make only operations it has been allowed to do. Chapter 10, “Overview of OAuth in SharePoint 2013,” covers this topic in depth. The JavaScript and markup that you added to the Default.aspx page dynamically added a style sheet link to the page, the source of which was the CSS from your SharePoint site. It defines the styles it uses to show the UI with the same fonts and styles as SharePoint.

As with traditional Web Parts, you may also configure App Parts with custom properties. You can do this in the Elements.xml file for the App Part. App Parts support the following types of custom properties:

  • String: Gives a simple text box input field
  • Int: Renders as an input field that only accepts integers
  • Boolean: Renders as a check box field
  • Enum: Renders as a drop-down field

For example, if you wanted your App Part to accept a configuration property where the user could choose from one of three options, you could use the following XML:

<Property Name="colorProp" Type="enum" RequiresDesignerPermission="true" 
DefaultValue="R" WebCategory="My App Part Settings" WebDisplayName="Fav Color">
  <EnumItems>
    <EnumItem WebDisplayName="Red" Value="R"/>
    <EnumItem WebDisplayName="Green" Value="G"/>
    <EnumItem WebDisplayName="Blue" Value="B"/>
  </EnumItems>
</Property>

This code would render as shown in Figure 6-7.

Additionally, you can choose to pass the value set for these properties to your App Part via the URL by setting them as tokens in the Src attribute on the Content node in the Elements.xml file:

<Content Type="html" 
Src="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}& Property1=_ colorProp _" />

Ribbon and Action Menus

The ribbon was first introduced in SharePoint 2010 and provides the central location for all actions that a user may want to take on documents and other data. In SharePoint 2010, developers could include custom actions for their applications in the ribbon; SharePoint applications also allow this customization. This enables you to include actions where users expect them, alongside all the other standard actions SharePoint provides (see Figure 6-8).


NOTE When designing your SharePoint application consider including your application’s common actions on the ribbon. Doing so makes them easy for users to find and provides a consistent user experience.

The Action menu is a context-aware menu on items in a SharePoint list or library. For example, in a SharePoint document library the Action menu exposes common functions such as Check In and Check Out (see Figure 6-9). Another term commonly used for this menu is ECB (Edit Control Block). SharePoint applications allow you to include additional actions on this menu. For example, it is a great location to expose your application’s functions that apply to a single list item. You should also consider including the action in the ribbon for consistency; however, the ECB offers quicker access for the user, so including it in both locations is advised.

To get a feel for how to develop with the Ribbon in a SharePoint application try the following exercise that walks you through the process.


TRY IT OUT: Adding a Custom Action to Your Application
In this exercise you add a new Ribbon action to your application that, when clicked, will call your application. You must have completed the App Part exercise, “Building Your First SharePoint Application,” in the previous section before starting this example.
1. Ensure you have the MyFirstSharePointApp solution open in Visual Studio 2012.
2. Right-click the MyFirstSharePointApp project and select Add ⇒ New Item. In the Add New Item dialog select UI Custom Action (Host Web) and name it MyAppAction. Click Add.
3. Open the Elements.xml under MyAppAction if it is not already open.
4. Replace the entire contents of the file with the following code. This defines your Ribbon button. The CustomAction node contains information specifying that the action resides in the ribbon and should be present on all custom lists as defined by the RegistrationId attribute. The CommandUIDefinition node defines the button and that it should reside inside the Manage tab in the list item Ribbon. Finally, the CommandUIHandler node specifies the URL that should be called when the action is initiated. In this example, you also pass the IDs of the list and list item to the page so that they can be used in the action code.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="00ec7345-f310-4fb1-a836-5cef4d0ad2fa.MyAppAction"
                RegistrationType="List"
                RegistrationId="100"
                Location="CommandUI.Ribbon"
                Sequence="100"
                Title="MyAppAction action">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListItem.Manage.Controls._children">
          <Button
              Id="Ribbon.Library.Connect.PropertyViewer"
              Alt="MyAppAction action"
              Sequence="115"
              Command="Invoke_CustomAction"
              LabelText="MyAppAction action"
              TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
            Command="Invoke_CustomAction"
            CommandAction="~remoteAppUrl/Pages/Default.aspx?{StandardTokens}
&amp;ListURLDir={ListUrlDir}&amp;SelectedListID={SelectedListId}
&amp;SelectedItemID={SelectedItemId}"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
5. Open the Default.aspx.cs page.
6. Replace the entire Page_Load method with the following code:
protected void Page_Load(object sender, EventArgs e)
{
    var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
    var hostWeb = Page.Request["SPHostUrl"];
 
    using (var clientContext = TokenHelper.GetClientContextWithContextToken (hostWeb,contextToken, Request.Url.Authority))
    {
        clientContext.Load(clientContext.Web,
            web => web.Title);
 
        clientContext.ExecuteQuery();
        Response.Write(clientContext.Web.Title);
        clientContext.ToString();
                
        if (Page.Request["SelectedListID"] != null)
        {
            Guid listId = Guid.Parse(Page.Request["SelectedListID"]);
 
            Microsoft.SharePoint.Client.List list = 
clientContext.Web.Lists.GetById(listId);
 
            clientContext.Load(list,
                l => l.Title);
 
            clientContext.ExecuteQuery();
 
            Response.Write("<p>Action taken on:" + list.Title + "</p>");
        }
    }
}
7. Press F5 to compile, package, deploy, and debug your application. When the process completes, a browser launches to a page asking, “Do you trust MyFirstSharePointApp?” Click Trust It to continue. You should see your application listed when the compile and deploy operation is complete.
8. Click the Add an app link and select a Custom List. Call it My Custom List and then click Create.
9. Click My Custom List from the list.
10. Click the Items ribbon tab. You should see your custom action within the Manage group as shown in Figure 6-10.
11. Click the MyAppAction ribbon action. If a security warning appears, click the option to continue to the site. (This warning appears if your application site is not correctly secured with SSL in your development environment.)
12. You should see your application with the text “Action taken on: My Custom List” on the page. The application has used the Client-Side Object Model to call back into SharePoint and retrieve the name of the list from which your application custom action was triggered.
How It Works
In this exercise you added a custom action button to the SharePoint Ribbon. As part of the button configuration you specified a page in your application as the destination when the button is clicked. Passed along on the query string was an additional piece of information about the ID of the list that was in the user’s context when it was clicked. The app’s page code used that ID to call back into SharePoint via a CSOM call to retrieve the list’s DisplayName. Similar to the previous exercise, the Ribbon button definition was packed up as part of your app’s package and deployed to SharePoint. There are many different locations where you can choose to place custom Ribbon buttons. You can find a list of these on MSDN (http://msdn.microsoft.com/en-us/library/ee537543.aspx).

Navigation

To ensure a consistent way for users to find and interact with apps, SharePoint 2013 provides two standardized navigational elements:

App developers have little control over the style and location of the Quick Launch navigation because it is provided by SharePoint and the inclusion of your app in this navigation is dictated by the user. However, app developers have more control over the appearance of their application’s tiles available in the Site Contents section of a SharePoint 2013 site. You are able to specify the name and tile icons shown.

As a developer you can specify the following properties via the AppManifest.xml file in your application:

  • Name
  • Title (shown in the SharePoint site UI)
  • Tile icon (96 × 96 PNG)

Try out the following exercise to learn how to change the look of your application with a custom tile and name.


TRY IT OUT: Customizing Your Application’s Name and Tile
In this exercise you set a new tile image for your application. You must have completed the “Building Your First SharePoint Application” in the “App Parts and Pages” section before starting this example.
1. Ensure you have the MyFirstSharePointApp solution open in Visual Studio 2012.
2. Locate and double-click the AppManifest.xml file in the MyFirstSharePointApp project to open it in Design view.
3. Change the title of the application to My First SharePoint Application.
4. Click Browse next to the Icon path text box. From the downloaded code package for this chapter locate the MyAppIcon.png file, select it, and click Open.
5. Press F5 to package and deploy your application.
6. After the app deploys, you should see its new title and icon displayed (see Figure 6-13).
How It Works
In this exercise you customized the title and icon for your application. A SharePoint application’s configuration properties are stored in the AppMenifest.xml file. Visual Studio 2012 provides a designer-based interface over this file so you can configure these properties easily; however, you can also go into the XML itself to set them.

Events and Logic Integration

Providing a UI for users is usually the most prominent aspect of any application. However, responding to the actions users take either within an application, or to interact with an application, is also extremely important. SharePoint applications provide the ability to both respond to activities within your application (such as a button click) and respond to activities within SharePoint (such as a document being checked out).

Responding to activities within your application is very straightforward. Your application’s UI and code run remotely from SharePoint and are simply surfaced via App Parts and Pages. For that reason, responding to an event such as a button being clicked in your application is entirely tied to your application’s programming framework. For example, if your app is built with ASP.NET then you simply catch the OnClick event for an ASP.NET button. SharePoint does not get in your way for these types of events.

The following exercise shows you how to add code behind a button in your SharePoint application that responds when it is pressed.


TRY IT OUT: Responding to Events Within Your Application (EventsandLogicintegreation.zip)
In this exercise you add a button to your application and include code that is run when it is pressed. You must have completed the “Building Your First SharePoint Application” in the “App Parts and Pages” section before starting this example.
1. Ensure you have the MyFirstSharePointApp solution open in Visual Studio 2012.
2. Open the Default.aspx file under the MyFirstSharePointAppWeb project.
3. Insert the following code directly after </div>.
<asp:Button ID="Button1" runat="server" Text="Do Something" 
OnClick="Button1_Click" /><br />
<asp:Label ID="txtUser" runat="server" Text=""></asp:Label>
4. Open the Default.aspx.cs file.
5. Replace the Page_Load method with the following code:
protected void Page_Load(object sender, EventArgs e)
{
    var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
    var hostWeb = Page.Request["SPHostUrl"];
 
    if (!IsPostBack)
    {
        Button1.CommandArgument = contextToken;
 
 
        using (var clientContext = 
TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken,
 Request.Url.Authority))
        {
            clientContext.Load(clientContext.Web, web => web.Title);
            clientContext.ExecuteQuery();
            Response.Write(clientContext.Web.Title);
            clientContext.ToString();
        }
    }
}
The Button1.CommandArgument = contextToken; line ensures that the contextToken is stored for later use on postback events when the button is clicked. You need it to make subsequent CSOM calls.
6. Add the following new method after the Page_Load method:
protected void Button1_Click(object sender, EventArgs e)
{
    var contextToken = ((Button)sender).CommandArgument;
    var hostWeb = Page.Request["SPHostUrl"];
 
    using (var clientContext = 
TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken,
 Request.Url.Authority))
    {
        clientContext.Load(clientContext.Web.CurrentUser);
        clientContext.ExecuteQuery();
 
        txtUser.Text = clientContext.Web.CurrentUser.LoginName; 
    }
}
7. Press F5 to package and deploy your application.
8. After your app deploys, add your app’s App Part to the homepage of your site by clicking Page ⇒ Edit ⇒ Insert ⇒ App Part. Select MyAppPart from the list and then click Add.
9. Inside your App Part you should now see a button called Do Something. Click it.
10. You should now see your full login name displayed directly below the button, as shown in Figure 6-14.
How It Works
In this exercise you added a button to your application and responded to it being clicked. Nothing is particularly special about this button over and above a standard ASP.NET button; however, it is worth understanding the role of the contextToken and the need to keep it between postbacks to your code so that further calls to the CSOM can be made. In the exercise you stored it in the CommandArgument for the button; however, the same could have been achieved in a variety of other ways, such as a hidden control on the page. The important thing is that it is in a location that you are able to retrieve at a later time during a postback event — you need this context in order to call SharePoint via the CSOM on subsequent requests.

For responding to events that occur inside SharePoint, such as a document’s being saved or updated, SharePoint provides event receivers. In SharePoint 2010 developers could use event receivers to receive events from SharePoint when a user took certain actions such as checking in a document or saving a list item. SharePoint 2013 also provides event receivers that allow applications to respond to events occurring within a SharePoint site. The primary difference from SharePoint 2010 is that event receivers now trigger code that runs remotely outside the SharePoint process in your application’s code. They do this via a commonly defined Web service interface. This means the code that you want to respond to events could reside in almost any system you like, as long as it is callable over HTTP/HTTPS from the SharePoint Server or Office 365. An example might be your application code that runs in Windows Azure.


NOTE For a deeper look into remote event receivers please read Chapter 12, “Remote Event Receivers in SharePoint 2013.”

Data Integration

At the heart of every application is data, which is typically what users want to work with within your application. SharePoint provides a number of out-of-the-box options for storing and working with data. These options fall into two categories:

  • Storing and manipulating data within SharePoint
  • Working with data that lives external to SharePoint

From the very first version of SharePoint, the goal has been to make working with data simple and straightforward for users. The simplest example of this is the concept of list data. Users are able to store and work with tabular style data via a common Web interface. Many see using lists analogous to using a table of data in a database. SharePoint applications can also take advantage of these same data storage capabilities natively. By using lists SharePoint offers developers the ability to take advantage of many of the data storage capabilities that SharePoint provides without having to reinvent the wheel. If used properly, SharePoint can save time and effort and potentially reduce the management and support costs of your operation.

At the core of the data storage capabilities within SharePoint are the following:

  • Lists: For storing structured data, much like in a table
  • Libraries: For storing unstructured data, such as in a document or file

SharePoint provides a comprehensive set of APIs for developers to use within applications to interact with and manipulate data that resides in SharePoint. For SharePoint applications those APIs are exposed in the Client-Side Object Model (CSOM).


NOTE Chapter 9 goes more in depth on Client-Side Object Model (CSOM) and the various APIs available in it.

To get a better feel for the data storage capabilities SharePoint provides, try out storing data in lists within SharePoint in the following exercise.


TRY IT OUT: Storing Data in SharePoint Using the Client-Side Object Model (DataIntegration.zip)
In this exercise you create new items in a SharePoint list using the CSOM API set. You must have completed the “Building Your First SharePoint Application” in the “App Parts and Pages” section before starting this example.
1. Ensure you have the MyFirstSharePointApp solution open in Visual Studio 2012.
2. If you haven’t already done so in a previous exercise create a new custom list in your site called My Custom List (choose Site Contents ⇒ Add an App ⇒ Custom List. Call it My Custom List and then click Create.)
3. Open the Default.aspx file under the MyFirstSharePointAppWeb project in Visual Studio.
4. Open the Default.aspx.cs file and replace the Button1_Click method with the following:
protected void Button1_Click(object sender, EventArgs e)
{
    var contextToken = ((Button)sender).CommandArgument;
    var hostWeb = Page.Request["SPHostUrl"];
 
    using (var clientContext = 
TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken,
 Request.Url.Authority))
    {
        Microsoft.SharePoint.Client.List list = 
clientContext.Web.Lists.GetByTitle("My Custom List");
 
        for (int i = 0; i < 10; i++)
        {
            ListItemCreationInformation itemCreateInfo = 
new ListItemCreationInformation();
            Microsoft.SharePoint.Client.ListItem newListItem = 
list.AddItem(itemCreateInfo);
            newListItem["Title"] = "New Item " + i.ToString();
            newListItem.Update();
        }
 
        clientContext.ExecuteQuery();
    }
}
5. Press F5 to package and deploy your application.
6. After the app deploys, add your app’s App Part to the homepage of your site by selecting Page ⇒ Edit ⇒ Insert ⇒ App Part. Select MyAppPart from the list, and then click Add.
7. Inside your App Part you should now see a button called Do Something. Click it. A ServerUnauthorizedAccessException error appears, as shown in Figure 6-15. This is because your application currently only has Read access to your SharePoint site. You need to modify your app’s permissions.
8. Click Stop Debugging in Visual Studio.
9. Double-click the AppManifest.xml file under MyFirstSharePointApp.
10. Under Permission Settings, add the following options:
  • Scope: List
  • Permission: Write
11. Press F5 to package and deploy your application.
12. Notice that SharePoint now asks you which list you want to allow it access to edit or delete items in. Select My Custom List from the drop-down menu. Click Trust It to continue.
13. You might need to re-add your App Part due to the change in app security settings.
14. Click Do Something in your App Part.
15. After the operation completes, open My Custom List in the SharePoint site. You should see that ten items have been added to the list, as shown in Figure 6-16.
How It Works
In this exercise you added list items to a SharePoint list. You configured your application to ask for permission to have edit rights on the list. SharePoint apps can ask for access to various security scopes of varying levels. Your application should only demand the permissions it needs to operate correctly. An app asking for too many permissions might make a user unwilling to grant them and therefore unable to use the app. Additionally, users cannot grant applications permission to resources that they themselves do not have appropriate access to.

NOTE You can read more about all the available permission scopes and rights on MSDN (http://msdn.microsoft.com/en-us/library/fp142383(v=office.15).aspx).


Additionally, SharePoint offers developers a range of mechanisms and APIs for integrating with data that lives outside of SharePoint. Although the data exists external to SharePoint, these APIs and features offer the ability to integrate with data much the same way you would with data stored inside SharePoint itself. The capability is called Business Connectivity Services and you can read more about these advanced data integration options in Chapter 13, “Building Line-of-Business Solutions Using Business Connectivity Services.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset