Create a calculated field using Visual Studio 2010 in SharePoint

Steps Involved:

  1. Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
  2. Go to File tab, click on New and then click on Project.
  3. In the New Project dialog box, expand the Visual C# node, and then select the SharePoint 2010 node.
  4. In the Templates pane, select Empty SharePoint Project.
  5.  Enter the Name as CalculatedColumn and then click OK.
  6.  In the solution explorer, right click on the solution and then click on Add -> New Item.
  7. Select the Empty Element from the templates.
  8. Enter the Name as CalculatedColumn and then click on Ok.
  9. Open Elements.xml and replace with the following code.

 

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <Field ID="{07C57649-CBA9-4FF7-A892-9E9A3705541C}"

         Name="CalculatedField"

         DisplayName="Calculated Field"

         Type="Calculated"

         ResultType="Text"         

         Description="Calculated Field Example"

         Group="Vijai Site Columns" >

    <Formula>=[Title]</Formula>

  </Field>

</Elements>



Deploy and Test:

Deploy the solution. Go to the SharePoint site, Site Actions -> Site Settings -> Galleries -> Site Columns -> Vijai Site Columns group. You could be able to see the new created calculated column.


CalculatedField.png