Tuesday, November 12, 2013

Configure apps to be autohosted in SharePoint Online in SharePoint 2013, Create a basic Autohosted app for SharePoint 2013, How to Install the Autohosted App in SharePoint 2013

http://code.msdn.microsoft.com/SharePoint-2013-Configure-41146212
http://msdn.microsoft.com/en-us/library/office/fp179886.aspx
vs2012 -> file -> new -> project c# -> office/SharePoint -> apps -> apps for SharePoint 2013 -> "FirstAutohostedApp"
 

Solution "FirstAutohostedApp" -> FirstAutohostedAppWeb -> Default.aspx
<form id="form1" runat="server">
        <div>
            <div>
                <h2 style="font-family: Segoe UI; font-size: xx-large; font-weight: 100; font-style: normal; color: White">composed looks on the SharePoint host website</h2>
            </div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
                Text="GET THE COMPOSED LOOKS" BackColor="#00FFFF" ForeColor="Black" Font-Size="Large"
                Style="font-family: 'Segoe UI'; border-style: none; text-wrap: normal; font-weight: normal"
                Height="210px" Width="239px" />
            <asp:Literal ID="Literal1" runat="server"><br /><br /></asp:Literal>
            <asp:GridView ID="GridView1" runat="server" BackColor="#808080" ForeColor="White"
                BorderColor="#0033CC" BorderStyle="None" Caption="THE COMPOSED LOOKS"
                CaptionAlign="Left" CellPadding="5" Style="font-family: 'Segoe UI'" GridLines="None"
                HorizontalAlign="Left">
                <AlternatingRowStyle BackColor="White" ForeColor="Black" />
            </asp:GridView>
        </div>
    </form>

Solution "FirstAutohostedApp" -> FirstAutohostedAppWeb -> Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace FirstAutohostedAppWeb.Pages
{
    public partial class Default : System.Web.UI.Page
    {
        SharePointContextToken contextToken;
        string accessToken;
        Uri sharepointUrl;
        protected void Page_Load(object sender, EventArgs e)
        {
            TokenHelper.TrustAllCertificates();
            string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);
            if (contextTokenString != null)
            {
                contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
                accessToken = TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;
                Button1.CommandArgument = accessToken;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string accessToken = ((Button)sender).CommandArgument;
            if (IsPostBack)
            {
                sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
            }
            string oDataUrl = "/_api/Web/lists/getbytitle('Composed Looks')/items?$select=Title,AuthorId,Name";
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + oDataUrl);
            request.Method = "GET";
            request.Accept = "application/atom+xml";
            request.ContentType = "application/atom+xml;type=entry";
            request.Headers.Add("Authorization", "Bearer " + accessToken);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            XDocument oDataXML = XDocument.Load(response.GetResponseStream(), LoadOptions.None);
            XNamespace atom = "http://www.w3.org/2005/Atom";
            XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
            XNamespace m = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
            List<XElement> entries = oDataXML.Descendants(atom + "entry")
                                     .Elements(atom + "content")
                                     .Elements(m + "properties")
                                     .ToList();
            var entryFieldValues = from entry in entries
                                   select new
                                   {
                                       Title = entry.Element(d + "Title").Value,
                                       AuthorId = entry.Element(d + "AuthorId").Value,
                                       Name = entry.Element(d + "Name").Value
                                   };
            GridView1.DataSource = entryFieldValues;
            GridView1.DataBind();
        }
    }
}

Solution "FirstAutohostedApp" -> FirstAutohostedApp -> AppManifest.xml
Go to "Permission" and set "Web" scope as "Read" Permission.
Go to "Prerequisites" and set "autohosting prerequisite name" as "Web Site"(select from drop-down)

http://blogs.msdn.com/b/richard_dizeregas_blog/archive/2013/03/04/sharepoint-2013-app-deployment-through-quot-app-stapling-quot.aspx
Solution "FirstAutohostedApp" -> FirstAutohostedApp -> Right Click -> Publish

Now go to this path "FirstAutohostedApp\FirstAutohostedApp\bin\Debug\app.publish\1.0.0.0". Here we can find the our app name as "FirstAutohostedApp.app"

To install the autohosted app:-
-------------------------------------------
1. Log in to Microsoft SharePoint Online as a tenant administrator. [https://portal.microsoftonline.com/default.aspx] [Sign up for an Office 365 Developer Site -> "http://msdn.microsoft.com/en-us/library/fp179924.aspx"]
2. On the Admin drop-down menu at the top of the page, choose SharePoint.
3. On the SharePoint Administration Center page, choose apps, Click on "App Catalog".


6. Now to "Site Content" and click an "Add an App"

7. Now Click on "From you organization", then a pop up window open. Click on "Trust It" Button. after click on "Trust It" page will be redirect to "Site Content" Page

8. in "Site Content" Page select our App "FirstAutohostedApp" and Click on "Deployment" option.

9. Here we can deploy App in Three ways
1. Site Collection
2. Managed Path
3. Site Template
If we want remove we can remove from here only by removing 'Site Collection' or 'Manage Path' or 'Site Template'

10. Now go to Developer Site (Developer site means the site created using "Developer" Template) [https://sreekanthapp.sharepoint.com/sites/app/_layouts/15/start.aspx#/SitePages/DevHome.aspx]
And go to 'Site Content'. Here we can find out our "FirstAutohostedApp" deployed successfully.

11. Now Click on "FirstAutohostedApp" App. the App will open in new tab with it own url.
Now Click on "Get the composed look" link. then the page populated with all composed look infomation.
Thank You.

No comments:

Post a Comment

Featured Post

Mention a Channel or Team – Power Automate

Mention a Channel or Team – Power Automate graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/messages Channel: ---------- {   ...

Popular posts