Friday, 18 December 2015

Birthday reminder using SharePoint list

If you have SharePoint 2007 and up, AND it is the enterprise version of SharePoint, then you can use what's called Information Management Policies.
  1. Create a SharePoint list (custom list template) with all the people (in a people picker field) and their birthday (in a date field)
  2. Create a SharePoint Designer workflow on that list, that has one action: Send an email.  Put the birthday person's name in the TO  box of the email, and make the subject and body say whatever you want. 
  3. Publish the workflow.
  4. Go to the list's advanced settings, and change 'allow mgmt of content types' to YES.
  5. In list settings in the list of content types, there will only be one, called Item.  Click Item.
  6. Click Information Management Policy settings.
  7. Click "define a policy" and click OK.
  8. check the box next to "enable expiration"
  9. next to "a time period based on this item's properties, pick your birthday field + 1
  10. next to 'perform this action" choose to run a workflow
  11. Pick the name of the workflow you created at step 2

This will run every night and if it's a person's birthday they will get an email... the next day.

Friday, 20 November 2015

Modified and Created date in List View not showing current year - SharePoint 2013

In SharePoint 2013, list view we generally face this issue with Created or Modified Date where is done not show the Year. As seen in screenshot:

This is because, by default SharePoint shows date in Friendly format.

A quick workaround we can apply is to

  1. Go to List Settings
  2. Click on Modified or Created date column
  3. Changes Display format to Standard
  4. Done.
Then dates will be displayed in mm/dd/yyyy format.

Friday, 3 July 2015

How to get current year and current month get selected in SharePoint column

I have added Year column in SharePoint list and I want the default value to be current year.
To do this in default value of a column, select calculate value and put below formula in Text box


Similarly to select current month in moth column put below formula in Text box:


Hope this helps!!!!

Working with Checkbox in SharePoint

In below code we will see, how to add multichoice chekcbox field in list, add item with checkbox field and get value from chekcbox field.

using System;
using System.Collections.Specialized;
using Microsoft.SharePoint;

namespace ConsoleApp
    class Program
        static string listTitle = "My Custom List";
        static string fieldTitle = "Gift Options";
        static string fieldInternalName = null;

        static void Main(string[] args)
            using (SPSite site = new SPSite("http://localhost"))
                using (SPWeb web = site.RootWeb)
                    SPList list = web.Lists.TryGetList(listTitle);
                    if (list != null)
                        // Add a multichoice field to the list.
                        StringCollection choices = new StringCollection();
                        choices.Add("Gift wrap");
                        choices.Add("Gift card");
                        choices.Add("Include gift receipt");

                        fieldInternalName = list.Fields.Add(fieldTitle, SPFieldType.MultiChoice, false, false, choices);

                        // Get a reference to the field.
                        SPFieldMultiChoice choiceField = (SPFieldMultiChoice)list.Fields.GetField(fieldInternalName);

                        // Create a field value with all choices selected.
                        // (A CheckBoxChoiceField control would have all boxes checked.)
                        SPFieldMultiChoiceValue values = new SPFieldMultiChoiceValue();
                        foreach (string choice in choices)

                        // Add an item to the list.
                        SPListItem item = list.Items.Add();
                        item[SPBuiltInFieldId.Title] = "Test item";
                        item[choiceField.Id] = values;

                        // Get the value of the field in the item.
                        string rawValue = item[choiceField.Id].ToString();
                        SPFieldMultiChoiceValue typedValue = new SPFieldMultiChoiceValue(rawValue);

                        // Print the value.
                        Console.WriteLine("The raw value is {0}", rawValue);
                        Console.WriteLine("The value delimiter is {0}", SPFieldMultiChoiceValue.Delimiter);
                        for (int i = 0; i < typedValue.Count; i++)
                            Console.WriteLine("The value at index {0} is {1}", i, typedValue[i]);
            Console.WriteLine("\nPress ENTER to continue....");

Hope this helps!!!

How to download all deployed wsp solution files in SharePoint

Usually SharePoint admin guys takes backup of content DB and all physical files if they want to create replica of existing SharePoint site when actual site is down.

But that will not complete solves the solution, if there are any custom solutions already deployed.

So, admin guys needs those solution files.
To get those solution files which are deployed in SharePoint use the following power shell command to get all deployed solution files.

$pathName = "<PATH to Save files>"
foreach ($solution in Get-SPSolution)   
     $solid = $Solution.SolutionID
     $title = $Solution.Name
     $filename = $Solution.SolutionFile.Name


Hope this helps!!!

When to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

Below table give us the idea on when to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

No value
No value
No value
No value
New value
Original value
Changed value
Original value
Original value
Changed value
Changed value
No value
No value
Original value
No value
No value

Hope this helps!!!

How to find out SPUser belongs to Specific Group

How can I find out programmatically if current user belongs to some group on sharepoint website?

We can use below code:

SPWeb site = SPContext.Current.Web;
SPGroup managerGroup = site.Groups["Your_Group_Name"];

bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup.ID);

Hope this helps!!!!

Friday, 26 June 2015

Publishing Feature activation failed. Exception: System.ArgumentException: Value does not fall within the expected range.

Today while activating publishing feature in Site Settings I was getting an error. When I checked log file using correlation id , it was showing unexpected error as:

Publishing Feature activation failed. Exception: System.ArgumentException: Value does not fall within the expected range.

Then i tried to activate feature using Powershell and it worked:

$siteUrl = "http://SharePoint:6435/"
$siteCollection = Get-SPSite $siteUrl
Enable-SPFeature "PublishingSite" -Url $siteCollection.Url -force
Enable-SPFeature "PublishingWeb" -Url $siteCollection.Url -force

Hope this helps.!!!!!!!

Wednesday, 27 May 2015

Reserved querystring parameter in Sharepoint

Below querystring parameters are reserved in SharePoint and using them may give unpredictable results.

  • FeatureId
  • ListTemplate
  • List
  • ID
  • VersionNo
  • ContentTypeId
  • RootFolder
  • View
  • FolderCTID
  • Mode
  • Type
  • PageVersion
  • IsDlg
  • Title
  • _V3List_

To ensure that the creation of the SPContext object does not fail your application should ensure that your query string parameters are different from those listed above.


Tuesday, 26 May 2015

How to exclude or skip part of page content from SharePoint search crawler

To do this we have to use the "noindex" class, like this,

<div class="noindex"> footer </div>

This will be helpful if you want to avoid footer to get crawled in search. Because of the fact that the footer is part of the master page the crawler may index every single page that inherits from the master page. This will cause misleading and wrong search results for the visitors of the site.

Monday, 25 May 2015

How to change default tile size in SharePoint 2013

Using a CSS can be approach to achieve this.

Add the following CSS inside the content editor webpart or add it to your custom css

<style type="text/css">
                height: 100px;

                height: 110px !important;
                width: 110px !important;

  ,, > a > div > span {
                height: 100px !important;
                width: 100px !important;

   > a > div > img {
                max-width: 100%;
                width: 100% !important;

                height: 100px;
                padding: 0;

                font-size: 11px;
                line-height: 16px;

  ,, {
                padding: 3px;

                background: none repeat scroll 0 0 #002E4F;
                font-size: 12px;
                line-height: 16px;
                min-height: 36px;
                min-width: 97px;
                padding-left: 3px;
                position: absolute;
                top: -36px;

                font-size: 11px;
                line-height: 14px;
                padding: 3px;


Hope this helps..!!!

How to find all document of particular content type

We can use below powershell to find documents of certain content type:

 $site = Get-SPSite("your-site-url");  
 foreach ($web in $site.AllWebs) {  
   $ctype = $web.ContentTypes["Your Content Type"]  
   $usages = [Microsoft.Sharepoint.SPContentTypeUsage]::GetUsages($ctype)  
   foreach ($usage in $usages) {  
    Write-Host $usage.Url  

To find it using code you can below lines of code

 using (SPSite siteCollection = new SPSite("http://localhost"))  
       using (SPWeb webSite = siteCollection.OpenWeb())  
         // Get the content type.  
         SPContentType obsolete = webSite.ContentTypes["Test"]; 
         // We have a content type.  
         if (obsolete != null)   
          IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);  
          // It is in use.  
          if (usages.Count > 0)   
            Console.WriteLine("The content type is in use in the following locations:");  
            foreach (SPContentTypeUsage usage in usages)  
          Console.WriteLine("The content type does not exist in this site collection.");  
      Console.Write("\nPress ENTER to continue...");  

Hope this helps.!!!!!!!

Change linked to item with edit menu to different column

Normally a SharePoint list links to an item using the “Title” field. But in some cases you want to hide Title Column and and add linked to item link to another column.

Now to link the Item to a specific column/field, you need to open the list in SharePoint designer and look for the <viewfields> tags.
And then add LinkToItem="TRUE" to whichever column you want the link.

   <FieldRef Name="field1"/><br/>  
   <FieldRef Name="field2"/><br/>  
   <FieldRef Name="field3" LinkToItem="TRUE"/><br/>  
   <FieldRef Name="field4"/><br/>  
   <FieldRef Name="field5"/><br/>  

Save and you are done.!!!!!!

Wednesday, 6 May 2015

Upload file into SharePoint doument library with metadata using PowerShell

In this post we will see how to upload the file into the document library and insert/update the metadata columns. I am having 1 people picker data types/user group columns and 1 single line of text columns.

Below is the PowerShell to upload documents in PowerShell and update the metadata:

        if((Get-PSSnapin | Where {$_.Name -
        eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
            Add-PSSnapin Microsoft.SharePoint.PowerShell;

           #Site Collection where you want to upload files
          $siteCollUrl = "YourSiteURL"
          #Document Library where you want to upload files
         $libraryName = "DocLibName"
         #Physical/Network location of files
          $reportFilesLocation  = "D:\FileUpload"

        $spSourceWeb = Get-SPWeb $siteCollUrl;
        $spSourceList = $spSourceWeb.Lists[$libraryName];

            if($spSourceList -eq $null)
           Write-Host "The Library $libraryName could not be found."

   $files = ([System.IO.DirectoryInfo] (Get-Item 
  foreach($file in $files)
    #Open file
   $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

   #Add file
   $folder =  $spSourceWeb.getfolder($libraryName)

   Write-Host "Copying file $file to $libraryName..."
   $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name,   
   [System.IO.Stream]$fileStream, $true)

$item = $spFile.Item;
$item["TextOrChoiceColumnInternalName"] = "New Value"
$spUser = Get-SPUser -Identity "domain\username" -Web $spSourceWeb;
$item["UserFieldInternalName"] = $spUser;
#Use SystemUpdate($false) if you don't want to increase the version of the item..

   #Close file stream
Write-Host "Files have been uploaded to $libraryName."

Using this PowerShell script you can upload documents with metadata.

To check in a file use:
$spFile.CheckIn("Checked In By Administrator")

To publish a file:
$spFile.Publish("Automatically published by Powershell")

To approve a file:
$spFile.Approve("Automatically approved by by Powershell");

Hope this helps!!!

How to access SharePoint server “Outgoing E-Mail Settings” from code?

Outgoing email setting are configured in central administration at path:

Central Admin -> System Settings -> Configure outgoing e-mail settings

Below is the code to access outgoing e-mail settings using object model:

//Get the site ID
Guid siteID = SPContext.Current.Site.ID;
protected string GetSMTPHostName()
    using (SPSite site = new SPSite(siteID))
      //Get the SMTP host name from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailServiceInstance.Parent.Name;
protected string GetFromEmailID()
    using (SPSite site = new SPSite(siteID))
      //Get the “from email address” from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailSenderAddress;


Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Tuesday, 5 May 2015

How to start the workflow for an item using PowerShell / C#

In this article we will be seeing how to start a workflow for an item using c# and powershell

Start a workflow using c#

class Program    {
        static void Main(string[] args)
            using (SPSite site = new SPSite("YourSiteURL"))
                using (SPWeb web = site.RootWeb)
                    SPList list = web.Lists["Test"]; 
                    SPListItem item=list.Items[0];
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPWorkflowAssociation association = list.WorkflowAssociations[0];
                    string data = association.AssociationData;
                    SPWorkflow wf = manager.StartWorkflow(item, association, data, true);

Start a workflow using powershell:

$site=Get-Spsite $siteURL

Hope this helps!!!!

How to get document library size using PowerShell?

Below is the PowerShell script which will show the size of Particular library:

    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=,             Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=,   Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

    $siteURL = "YourSiteURL" 
    $site = new-object Microsoft.SharePoint.SPSite($siteURL)

    foreach ($web in $site.AllWebs)
     foreach ($list in $web.Lists)

            if($list.BaseType -eq "DocumentLibrary")   

if($list.Title -eq "YourDocumentLibraryTitle")
        $listSize = 0
       foreach ($item in $list.items) 
              $listSize += ($item.file).length
         "Web: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1KB),2)+"KB"     

Hope this helps!!!!

Wednesday, 29 April 2015

Create a Custom Page Layout in SharePoint 2013

This is a Step-by-Step tutorial on how to Create a Custom Page Layout in SharePoint 2013.We will use the new Design Manager to Create a Layout (from an existing one) and then edit it in one of the editors like Notepad.Once the layout is Created and Uploaded to Master Page Gallery, you can edit the generated html file in an editor of your choice and upload it back to the Master Page Gallery.

Before you begin make sure that you have Publishing Feature enabled on your site and you see “Deisgn Manager” under Look and feel.

  1. Navigate to Site Settings -> Design Manager (under look and feel).
  2. Next in Design Manager select “6. Edit Page Layouts” and then “Create a page layout”
  3. Now Create a Custom Page layout using the Article Page Content type.
  4. When the Layout is Created, it gets available in “Edit Page Layouts” list and the “Master Page gallery” of the site.The Layout Page will be in Drafts mode until you publish it as a major version.
  5. Next Edit the New Layout Page and save the Changes.In SharePoint 2013 for every Layout page two files – .aspx and html are created by default.

    For making Changes to the Custom Layout, you need to download the html file of your layout page and make Changes to it.The modified html file is then saved back to the MasterPage Page gallery where the corresponding .aspx file gets updated automatically.
  6. Once you have updated and saved the Layout page, you need to Publish the Layout page as a major version to make it available in Layouts list.
  7. Finally, Create a new Page with your Custom Layout.

Tuesday, 28 April 2015

How to get ULS Logs in SharePoint 2013 (Developer Dashboard)

If you are a SharePoint developer and have ran around SharePoint Admin teams for ULS Logs here is a quick solution for you. You can get the ULS Logs right from the server for any page that you ran through in Developer Dashboard.

Prerequisites – You need to Activate Developer Dashboard using the following Stsadm command.

stsadm -o setproperty -pn developer-dashboard -pv on

Once you have turned ON the developer dashboard you can open it using a small icon next to “Focus on Content”

Once the Developer Dashboard is Open, refresh the SharePoint site page and it will appear in the developer dashboard.

Click on the “ULS Logs” tabs and you will see the fetching message.

Once its done the ULS tab will be displayed with the Logs from the server.

How to set a page as Home Page in SharePoint 2013 site

In this post we will look at options to set a Custom Page as Home Page in SharePoint 2013 site.

Option 1: If you want to set a Custom Page as a Home Page in a typical SharePoint Team site, you can simply do that by Opening the Page and selecting Page tab in ribbon -> Make HomePage button to set this particular page as default Home Page for your site.

Option 2: Another option to set a Custom Page as Home Page in SharePoint 2013 Team site is by using SharePoint Designer 2013. If you have opened or created a Page in SharePoint Designer then you can right click on the page and select the option “Set as Home Page” to set it as a default home page of your SharePoint site.

Option 3: If you are using the Publishing site (or site with publishing feature enabled), you can simply use the old “Welcome Page” link in the Site settings to set the URL of a page this is the desired home page for your SharePoint site.

How to Add\Embed Video to SharePoint 2013 site page

In this post we will look at how to Add or Embed these videos on SharePoint 2013 page.

You can either use the default Video view page that you get when you add the video to SharePoint or you can use the Video embed code to add the video in SharePoint 2013 page.In this post we will look at where to add the embed code.

  1. Create Asset library in SharePoint and upload a Video in it
  2. Navigate to the site library where you added the video and click on video thumbnail.In the view Video page click on the code icon and open embed code page.
  3. Copy the embed code
  4. Now go to the sharepoint page where you display a video
  5. Click on Insert tab to Insert “Script Editor” Webpart.
  6. Next click on Embed Code in Insert Ribbon tab and add the copied Video code to it.



How to add a Youtube video in Sharepoint 2013

In SharePoint 2013 admins can now Insert an iframe element into an HTML field like Content editor webpat on a page. This will let users Embed dynamic content from other sites, such as videos or map directions on any SharePoint site page.

Any external domains that will be Inserted in Iframe should be added as approved domains in “HTML Field Security”. By default, certain trusted external domains are already approved for use in iframes.Site collection administrators can customize the field security settings by changing the default trusted external domains.

To add a Youtube Video add the “” Domain in “HTML Field Security” first. Lets look at the Steps-

  1. Navigate to Site Settings (top-level Site collection) -> HTML Field Security.
  2. Make sure the domain “” is added as permitted domain
  3. Navigate to your Youtube video and click on Share and then Embed. Copy the code from youtube
  4. Add a Content editor webpart on a page and then click on “Edit Source” in “Format Text” tab in Ribbon. Add copied code in the source
  5. Click Ok


Add Metadata navigation in SharePoint 2013

Metadata Navigation is one of the most useful features that was introduced in SharePoint 2010.By enabling this feature, users can Filter or narrow down the display of Documents within a document Library.The feature is highly beneficial while working with Document Libraries that has large number of documents.

Filtering documents by a Category or by a Metadata column can add a great value for efficient collaboration by the Team.Like the earlier SharePoint version, In SharePoint 2013, when enabled, the Metadata Navigation is added to the quick launch with the pre-Configured Navigation Hierarchies and Key Filters.

Lets look at the detailed Steps to Configure Metadata Navigation for a Document Library in SharePoint 2013.

  1. Enable “Metadata Navigation and Filtering” Site Feature in Site Settings
  2. Next Navigate to the Document Library Setting and select “Metadata navigation settings”.
  3. In the Metadata Settings select the Column that you want to Filter the Documents on.You need to add this Column to the Document Library first.
  4. Once you save the settings, a Filter Option appears in Quick Launch bar.

Tuesday, 21 April 2015

Verticle tile using promotion list in SharePoint 2013

We have seen in my earlier post. on how to create tiles menu in SharePoint 2013.

But what if you want these tiles in vertical order. There are two ways to achieve this. The one using jquery and other using CSS.

jQuery Solution

<script type=“text/javascript” src=“ “></script>
<script type=“text/javascript”>
$(document).ready(function () {
// Update this value to the number of links you want to show per row
var numberOfLinksPerRow = 4;

// local variables
var pre = “<tr><td><div class=’ms-promlink-body’ id=’promlink_row_”;
var post = “‘></div></td></tr>”;
var numberOfLinksInCurrentRow = numberOfLinksPerRow;
var currentRow = 1

// find the number of promoted links we’re displaying
var numberOfPromotedLinks = $(‘.ms-promlink-body > .ms-tileview-tile-root’).length;

// if we have more links then we want in a row, let’s continue
if (numberOfPromotedLinks > numberOfLinksPerRow) {

// we don’t need the header anymore, no cycling through links
$(‘.ms-promlink-root > .ms-promlink-header’).empty();

// let’s iterate through all the links after the maximum displayed link
for (i = numberOfLinksPerRow + 1; i <= numberOfPromotedLinks; i++) {

// if we’re reached the maximum number of links to show per row, add a new row
// this happens the first time, with the values set initially
if (numberOfLinksInCurrentRow == numberOfLinksPerRow) {

// i just want the 2nd row to

// create a new row of links
$(‘.ms-promlink-root > table > tbody:last’).append(pre + currentRow + post);

// reset the number of links for the current row
numberOfLinksInCurrentRow = 0}

// move the Nth (numberOfLinksPerRow + 1) div to the current table row
 $(‘#promlink_row_’ + currentRow).append($(‘.ms-promlink-body > .ms-tileview-tile-root:eq(‘ + (numberOfLinksPerRow) + ‘)’));

// increment the number of links in the current row
numberOfLinksInCurrentRow++; Â }

This uses the CDN at, so if your server does not have internet access you will need to copy this file locally.
Note that you can set the number of columns to wrap the quick links. This is the major advantage of using the jQuery script over the CSS.



width: 100%;

Nice and simple. Great for a one column left or right nav.


Related Posts Plugin for WordPress, Blogger...