Thursday, October 17, 2013

SharePoint 2013: App Development Environment

To develop apps on SharePoint 2013 there are various configurations which are required to make your environment ready for SharePoint 2013 app development. Following settings would be required as given in below sequence to make SharePoint ready for app development.

Make sure to start following services
  1. App Management Service
  2. SharePoint Foundation Subscription Setting Service

Service Applications
Make sure to configure following service applications
  1. App Management Service Application (this can be done from Central Administration)
  2. SPSubscriptionSettingsServiceApplication (this wont be visible in Central administration so it should be configured using PowerShell script)

DNS Settings
  1. Create host record for SharePoint site 
  2. Create forward look-up zone (you can name it
  3. Create an alias in zone, this alias should point to the SharePoint site host created in step 1

Web Application
  1. Configure App URL from central administration under app configuration section
  2. Create  SharePoint web application with host header which you created a host name in step 1 under DNS setting

Monday, October 14, 2013

Top 10 on Microsoft TechNet Wiki Leaderboards [October-2013]

Glad to see myself in top 10 list on Microsoft TechNet wiki contribution

Here is how the weekly leader board displayed on Microsoft TechNet

Sunday, October 13, 2013

C# code to create Site Column, Content Type, and add fields to Content Type

You can use below code to create following:-
1. Site Columns
2. Content Types
3. Add Fields to Content Type

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;

namespace LAB
    public static class SPDevUtility
        public static SPContentType CreateSiteContentType(SPWeb web, string contentTypeName,
        SPContentTypeId parentItemCTypeId, string group)
            if (web.AvailableContentTypes[contentTypeName] == null)
                SPContentType itemCType = web.AvailableContentTypes[parentItemCTypeId];
                SPContentType contentType =
                    new SPContentType(itemCType, web.ContentTypes, contentTypeName) { Group = @group };
                return contentType;
            return web.ContentTypes[contentTypeName];

        public static SPField CreateSiteColumn(SPWeb web, string displayName,
            SPFieldType fieldType, string groupDescriptor)
            if (!web.Fields.ContainsField(displayName))
                string fieldName = web.Fields.Add(displayName, fieldType, false);
                SPField field = web.Fields.GetFieldByInternalName(fieldName);
                field.Group = groupDescriptor;

                return field;

            return web.Fields[displayName];

        public static void AddFieldToContentType(SPWeb web, SPContentTypeId contentTypeId, SPField field)
            SPContentType contentType = web.ContentTypes[contentTypeId];

            if (contentType == null) return;

            if (contentType.Fields.ContainsField(field.Title)) return;

            SPFieldLink fieldLink = new SPFieldLink(field);