Blog

Programmatically get the calculated field formula in SharePoint 2010

Posted 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();
                    }
                }
            }
        }
    }
}


comments
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts