Monday, March 20, 2017

Use of SharePoint Designer 2013

Following are the high level list of features and functionality that we can do using SharePoint Designer 2013
  1. Edit Site
a.      Create list/libraries/Sites
b.      Create site pages
c.      Create Web Part Pages
d.      Create/edit Master pages
e.      Create custom new form  
f.       Copy/move/delete items
g.      Create content types/columns/external content types/site assets
h.      Site Groups
2. Create Workflows
a.      Workflow Actions
b.      List Workflow  
b.      Reusable Workflow  
c.      Site Workflow
d.      Package workflows  
e.      Loops in Workflow
3.      Create external Data sources
 4.      Integrate the Visio designer into SharePoint

 5.      Call REST Web Services

Friday, March 3, 2017

Personalize this page menu is missing

Version: SharePoint Server 2013

Issue: Personalize this page menu is missing on some pages.


If page is enabled with approval workflow, make sure that the approval status is 'approved'. Personalize this page menu will not show up if the Approval status of the page is in draft or pending status.

Thursday, March 2, 2017

Programmatically creating a field from the Custom field type

Environment: SharePoint Server 2013
Requirement: Programmatically create a field/column from a custom field type.

Following is a simple example with sample code to create a field from custom field type. In this example we are creating a custom field type (derived from SPFieldNumber) and add it to document library.

Note: I would recommend to refer to this MSDN post before this post to understand the entire steps involved to create a custom field type.

Creating the Custom Field Class.
The following example defines a custom control for displaying the custom field of type SPFieldNumber. The example overrides the OnAdded method to contain the logic while adding the custom field type in library/list.

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

namespace Prasath.SP
   class SampleHitCountField: SPFieldNumber
       public SampleHitCountField(SPFieldCollection fields, string fieldName)
           : base(fields, fieldName)

       public SampleHitCountField(SPFieldCollection fields, string typeName, string displayName)
           : base(fields, typeName, displayName)

       //Event triggered when new field is added to the document library
       public override void OnAdded(SPAddFieldOptions op)

           //Hide the field from new and edit form
           this.ShowInEditForm = false;
           this.ShowInNewForm = false;
           this.DefaultValue = "0";
           this.EnforceUniqueValues = false;
           this.Required = false;

Creating the Field Type Definition
The following example registers the custom field type. This file must be named in the format fldtypes*.xml

<?xml version="1.0" encoding="utf-8" ?>
   <Field Name="TypeName">SampleHitCountField</Field>
   <Field Name="TypeDisplayName">Total View Count</Field>
   <Field Name="InternalType">SampleHitCountField</Field>
   <Field Name="TypeShortDescription">Total View Count</Field>
   <Field Name="FieldTypeClass">Prasath.SP.SampleHitCountField, $SharePoint.Project.AssemblyFullName$</Field>
   <Field Name="ParentType">Number</Field>
   <Field Name="Sortable">TRUE</Field>
   <Field Name="Filterable">TRUE</Field>
   <Field Name="UserCreatable">TRUE</Field>
   <Field Name="ShowOnListCreate">FALSE</Field>
   <Field Name="ShowOnSurveyCreate">FALSE</Field>
   <Field Name="ShowOnDocumentLibrary">TRUE</Field>
   <Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
   <Field Name="ShowInListSettings">TRUE</Field>

Creating a Field from custom Field Type
Following is the method to create field from custom type
/// <summary>
       /// Create custom field as XML
       /// </summary>
       /// <param name="oId">Field GUID</param>
       /// <param name="strDisplayName">Unique Display Name of field</param>
       /// <param name="Required">Field required property</param>
       /// <param name="strFieldType">Custom field type</param>
       /// <param name="strFieldName">Custom field display name</param>
       /// <returns>string</returns>
       internal static string GetCreateFieldAsXml(Guid oId, string strDisplayName, bool Required, string strFieldType, string strFieldName)
           XmlElement element = new XmlDocument().CreateElement("Field"); // Creating the “Field” element for the Inner XML schema
           element.SetAttribute("ID", oId.ToString()); // Setting the GUID of the field from value passed
           element.SetAttribute("Type", strFieldType); // Setting the Parent Type name of custom type registered in the “Fldtypes*.xml” file
           element.SetAttribute("Name", strFieldName); // Setting the Type Display Name registered in the “Fldtypes*.xml” file
           element.SetAttribute("DisplayName", strDisplayName); // Any unique Display Name
           element.SetAttribute("Required", Required.ToString().ToUpper());
           return element.OuterXml; // Returning the OuterXML to create the field as XML

//Code to custom field as XML from custom field type
String strFieldasXML = GetCreateFieldAsXml(Guid.NewGuid(), “Hit Count Field”, false, "SampleHitCountField", “SampleHitCountField”);
web.Fields.AddFieldAsXml(strFieldasXML); //here 'web' is a SPWeb object

Wednesday, March 1, 2017

Retrieve SharePoint Document Icons programmatically

Environment: SharePoint Server 2013

Requirement: Retrieve SharePoint Document library icon based on the document type (extension).

Solution: Use SPUtility.GetCurrentGenericSetupPath to obtain the file path for sharepoint 2013 location and use System.IO.File.Exists() method to check if the file exists in the location.

Following method returns the file name and relative URL of the icon file location based on the extension parameter passed.

       /// <summary>
       /// Method to get the document icon path
       /// </summary>
       /// <param name="extn">document type</param>
       /// <returns>relative URL of the icon image file</returns>
       public static string GetDocumentIconPath(string extn)
               if (File.Exists(SPUtility.GetCurrentGenericSetupPath("template\\images\\ic" + extn + ".png")))
                   return "_layouts/15/images/ic" + extn + ".png";
               else if (File.Exists(SPUtility.GetCurrentGenericSetupPath("template\\images\\ic" + extn + ".gif")))
                   return "_layouts/15/images/ic" + extn + ".gif";
                   return "_layouts/15/images/icgen.gif";
           catch (Exception ex)
              //Handle Exception

//Call the above method by passing the File Type column value of a document library item.
String iconURL = GetDocumentIconPath(document.Item["File Type"].ToString();