Friday, July 26, 2013

How to Create an HTML MasterPage for SharePoint 2013

As I have stated before, HTML MasterPages are one of the big new things in SharePoint 2013, and even if they are not always the preferred option, it may prove handy in some cases (a bit of exploration of that topic in my previous article). So the question is: how to actually go about it?

1) Create your HTML structure
You can create the basic structure of the master page in any HTML editor of your liking, more or less forgetting about the SharePoint aspect altogether. I say more or less, not completely, because you need to understand what a MasterPage is, essentially, what its function is.

A MasterPage contains the basic structure of the pages, the wireframe of where elements are on every page. In SharePoint, it can also contain some controls like navigation and site logo and search. These controls are later added as snippets to the MasterPage. What you need to do now, is create the wireframe as an HTML page. 

Example (HTML5):

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
<link type="text/css" href="DemoStyles.css" />
</head>
<body>
    <header>
        <div id="sitelogo">[site logo control here]</div>
        <div id="headerright">
            <div id="subtitle">Company A Intranet</div>
            <div id="searcharea">[search control here]</div>
        </div>
    </header>
    <nav>[top navigation control here]</nav>
    <section id="mainarea">
        <nav>[left navigation control here]</nav>
        <div id="pagebody">
            [ContentPlaceHolderMain here]
        </div>
    </section>
    <footer>
        <span>Company A Intranet</span>
    </footer>
</body>
</html>


2) Create your CSS stylesheet (and graphics etc.)
You can test your site UI by adding the references to your stylesheet (and graphics) on the HTML page while still stored in your filesystem; simply change them later if the relative paths change after uploading everything to the server.

3) Upload your files to the server
Navigate to the top level site settings in your SharePoint Site Collections and open the MasterPages library under Web Designer Galleries category. Click Upload Document in the Ribbon, and browse for your HTML file and click Upload. Select HTML MasterPage as the Content Type of the file.



You can also add your CSS Stylesheet reference in the information form.

Upload your stylesheet and graphics as Design Files. You can create a separate folder for them too.


4) Convert your HTML file into a MasterPage
Navigate to the Design Manager in Site Settings, under Look and Feel and select Edit Master Pages. Note your HTML MasterPage in the list.



It still needs to be converted into a .master MasterPage, so click on Convert an HTML file to a SharePoint master page and select your MasterPage from the gallery.


Click Insert and SharePoint will convert your HTML page into a MasterPage, showing the MasterPage status as "Conversion successful".

Click on your MasterPage to open it in Preview.

5) Open your HTML MasterPage file for editing
You can either download a copy of the converted .html file from the MasterPages gallery or open the Top Level Site for editing in SharePoint Designer 2013 where you can edit the file on the fly and see the changes in the preview right away.


In SharePoint Designer: click to open the file, then click the Edit file -link.

You can see that with the conversion, SharePoint added a whole lot of code in the HTML version of the file in addition to creating the .master file. Do not delete the code added by SharePoint!

6) Add snippets to your .html MasterPage
In the browser, open the file in Preview, if you did not do this yet. Then, click on Snippets in the upper right hand corner of the Preview page.


This opens a new tab in the browser for selecting and customizing the snippets, i.e. the SharePoint controls.



Pick the snippet on the Ribbon, customize it as needed, then click on Copy to Clipboard and paste the code in the appropriate place in the HTML file.


If you are working in SharePoint Designer, save changes and refresh Preview to view the changes made by insterting the snippets.

When you are ready, save and close the HTML file and return to Design Manager in the browser.

7) Publish your design files
Navigate to the MasterPages gallery and publish your files. Your MasterPage is ready to be used.


Thursday, July 11, 2013

SharePoint 2013 - App Development


Pre-Requisite: Have your virtual machine ready with Microsoft SharePoint 2013 and Visual Studio 2012 installed on it.
This article is divided into following three sections:
  1. Setup App Catalog
  2. Develop a SharePoint-Hosted App
  3. Deploy the App

Setup App Catalog:

For App development in SharePoint 2013, first we need to setup an App Catalog. What is an App Catalog? App Catalog is a special Site Collection where all the apps are published and stored. App Catalog site collection is setup per web application. So once an app is hosted in an app catalog, it is available to all the site collections within that web application.
Below are the steps to create and setup an App Catalog to deploy a SharePoint-Hosted App:
  1. Go to the Central Administration and select Apps from the left menu
    2013-04-22-SharePoint2013AppDev-01.PNG
  2. From the App Management section, select Manage App Catalog
    2013-04-22-SharePoint2013AppDev-02.png
  3. On the Manage App Catalog page, select Create a new app catalog site and hit OK.
    2013-04-22-SharePoint2013AppDev-03.png
  4. On the Create App Catalog page, provide the required fields along with the Farm account and hit OK.
    2013-04-22-SharePoint2013AppDev-04.png
  5. Once done, you should see following screen.
    2013-04-22-SharePoint2013AppDev-05.png
  6. Browse to the App Catalog site and it should look like this:
    2013-04-22-SharePoint2013AppDev-06a.png
  7. Apps are designed to run from a separate Domain name. To configure that we need an entry in the Domain Name Server (DNS). I have created a new domain apps.com. * in the domain is used so that we can use the app name there.
    2013-04-22-SharePoint2013AppDev-07a.png
  8. You should be able to ping the domain name after its configured.
    2013-04-22-SharePoint2013AppDev-08a.png
  9. Run the following script to create a new service application running in its own pool
    2013-04-22-SharePoint2013AppDev-09a.png
    Script:

    01add-pssnapin "Microsoft.Sharepoint.Powershell"
    02 
    03$account = Get-SPManagedAccount Domain\go-SvcSpSetupDev
    04 
    05Remove-SPServiceApplicationPool -Identity SettingsServiceAppPool
    06 
    07$appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
    08 
    09$appSubSvc = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPoolSubSvc -Name SettingsServiceApp -DatabaseName SettingsServiceDB
    10 
    11$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication$appSubSvc

    Verify:
    Go to Central Administration -> Application Management -> Service Applications -> Manage Service Applications
    2013-04-22-SharePoint2013AppDev-10a.png
    You should be able to see SettingsServiceApp
    2013-04-22-SharePoint2013AppDev-11a.png
  10. Now, let's configure App URL.
    2013-04-22-SharePoint2013AppDev-12a.png
    Enter the domain and prefix
    2013-04-22-SharePoint2013AppDev-13a.png

Develop a SharePoint-Hosted App

  1. Launch Visual Studio 2012 and create an App for SharePoint 2013.
  2. Give the app name, site name and select SharePoint-hosted
    2013-04-22-SharePoint2013AppDev-14a.png
  3. Write your Client Object Model (CSOM) code in App.js.
  4. Select Build -> Publish and then Finish. You will get an App1.app ready to deploy.

Deploy the App

  1. Go to the App Catalog site and select Apps for SharePoint library.
  2. Upload App1.app here by selecting new app link.
    2013-04-22-SharePoint2013AppDev-15a.png
  3. Go to the home page and select Settings icon -> Add an app
    2013-04-22-SharePoint2013AppDev-16b.png
  4. Look for App1 and select it and then click Trust It. < style="text-align: center">2013-04-22-SharePoint2013AppDev-17b.png

  5. The App1 will take some time to get installed and will be visible in Site Content.
    2013-04-22-SharePoint2013AppDev-18b.png
    2013-04-22-SharePoint2013AppDev-19b.png
  6. Click the app to run it.
    2013-04-22-SharePoint2013AppDev-21.PNG
  7. If you observe the URL of the app. It looks something like this:

    http://[app prefix]-[app hash].[app domain]/[relative site URL]/[app name]/Pages/Default.aspx
    e.g.
    http://app-441ae93071a873.apps.com/sites/AppCat/App1/Pages/Default.aspx
  8. 2013-04-22-SharePoint2013AppDev-20.png
Ref 1: http://technet.microsoft.com/en-us/library/fp161234.aspx 
Ref 2: http://msdn.microsoft.com/en-us/library/jj164070.aspx