Blog

Programmatically get the calculated field formula in SharePoint 2010

By Vijai Anand Blogs | SharePoint 2010 Dec 03, 2012
In this blog you will see how to get the calculated field formula in SharePoint 2010 using SharePoint Object Model.

I have a custom list named “Employees' which has the following columns.

  • FirstName – Single line of text
  • LastName – Single line of text
  • FullName – Calculated Field

In this blog you will see how to get the calculated field formula using SharePoint Object Model.

Formula for FullName 

 =[LastName]&","&[FirstName]

Code Snippet:


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

namespace CalculatedField
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://shashankpc:2012/sites/test"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("Employees");
                    if (list != null)
                    {
                        SPFieldCalculated calculatedField = list.Fields.GetFieldByInternalName("FullName") as SPFieldCalculated;
                        Console.WriteLine(calculatedField.Formula);
                        Console.ReadLine();
                    }
                }
            }
        }
    }
}


COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs