Tuesday, March 19, 2013

SharePoint 2013 - How to create SharePoint Hosted App with App Part


Step 1: Create a new SharePoint-hosted app
In this Step, you will create a new SharePoint-hosted app and make a small number of changes to the code provided.

1.       Launch Visual Studio 2012 and create a new SharePoint-hosted App project and name it SharePoint App Part Demo
2.       In the New App for SharePoint dialog, set the name of the app to SharePointAppPartDemo
3.       Set the debugging site to https://URL/
4.       Host your app for SharePoint as SharePoint-hosted
5.       Click Finish to create the project
Step 2: Add Code for App Part Functionality
In this Step, you will add code to engage the app part functionalities of SharePoint
1.       Double-click the Default.aspx file in the Pages folder and add the following code after the < p>< /p> tag currently inside the < div>< /div> tag
        < p>
            I am the full screen SharePoint app.
        < /p>
2.       Add a new page to the SharePoint App Part Demo project by right clicking on Pages folder and selecting Add New Item
3.       Navigate to Office/SharePoint items and select the Page item and name it AppPart.aspx
4.       Open AppPart.aspx in the editor and replace all the code with the following
< %@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" language="C#" %>
< %@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
< %@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
< %@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
< WebPartPages:AllowFraming ID="AllowFraming" runat="server" />
< !DOCTYPE html>

< html xmlns="http://www.w3.org/1999/xhtml">
< head id="Head1" runat="server">
    < title>Demo App Part< /title>
    < !-- Add your CSS styles to the following file -->
    < link rel="Stylesheet" type="text/css" href="../Content/App.css" />

< /head>
< body>
    < div>I am the Demo App Part.< /div>
< /body>
< /html>  

5.       Add a new item to the SharePoint App Part Demo project by right clicking on SharePoint App Part Demo and selecting Add New Item
6.       Navigate to Office/SharePoint items and select the Client Web Part (Host Web) item and name it Demo App Part, click Add.
7.       In the Specify the client web part page dialog, click the Select or enter a URL for an existing web page radio button, select the AppPart.aspx page and click Finish.
Step 3: Deploy and Test the SharePoint App
  1. Deploy .app file to catalog site.
  2. Edit any page and add that app part to that page