0

I want to modify the column name of "Created" date. Since this is not possible directly, I want to create a site column and set the "Created" field to this column. This site column can be added to my list too. How can I achieve this ? How to set the Created field's value to Site column ?

EDIT

I'm using SP 2013 & VS 2013.

  • Instead of creating a site column, why dont you create a calculated column in your list with value from "Created" column.? – Karthik Jaganathan Jan 30 '14 at 12:32
  • Can you give me an example? I'm new to sharepoint. – Anish V Jan 30 '14 at 12:36
  • I can't find the type "Calculated" in visual studio! – Anish V Jan 30 '14 at 12:40
3

Follow the below steps,

  1. Navigate to your list and then Create a New column in your list with the required name.

  2. Select the type of the column to be "Calculated".

  3. In the "Formula" section, select the "Created" column.

  4. Select the return datatype.

  5. Click "Ok".

Use the below code to add a calculated column programmatically,

  using (SPSite site = new SPSite("http://serverName/sites/Vijai/"))        
        {           
         using (SPWeb web = site.OpenWeb())    
                {    
                    SPList list = web.Lists.TryGetList("Custom");        
                if (list != null)         
               {            
                ////Create a calculated field  
                   string calculatedColumn = list.Fields.Add("CalculatedColumn",SPFieldType.Calculated, false);                      
      ////Get the newly created calculated field         
                   SPFieldCalculated calculatedField = list.Fields[calculatedColumn] as SPFieldCalculated;    

                     ////Set the calculated field formula 

                           calculatedField.Formula = "=[Title]";  
                          ////Set the data type returned from this formula  
                          calculatedField.OutputType = SPFieldType.Text;                       
 ////Update the calculated field  
                calculatedField.Update();        
            }          
      }          
  }

Use the below code to add the column using Element.xml

<Field   Type="Calculated"   DisplayName="Name"  
EnforceUniqueValues="FALSE"   Indexed="FALSE"  
Format="Requiredformat"   LCID="1033"   ResultType="Text"  
ReadOnly="TRUE"   ID="{85353f64-8c8f-4424-ba81-bdc07b9880d6}"  
SourceID="{b9c7c8c2-7106-4219-84f9-b3d7cd0a9760}"   StaticName="Name" 
Name="Name"   ColName="Name"   RowOrdinal="0"   Required="FALSE"  
Percentage="FALSE"   Version="3"> 
<Formula>=[Created]</Formula></Field>
  • I'm not getting the type "Calculated" in that drop down. I'm creating my list from the visual studio. – Anish V Jan 30 '14 at 12:44
  • Now, I'm getting the Created field, but unable to get the Modified field!! Any idea ? – Anish V Jan 30 '14 at 13:49
  • @AnishV Please raise it as a new question, so that it will be helpful to others. – Karthik Jaganathan Jan 30 '14 at 13:58
0

Simple...you create your new column, set it to a lookup field then from the properties tab select the "List" and "Field" you want to set it to.

S

  • I don't want a column from another list, but from the current lists Created column. How can I do that ? – Anish V Jan 30 '14 at 12:39
  • Pretty sure you can...should be an easy one to test. – Stephen Jan 30 '14 at 12:40
  • I have tried that, but Created field is listing as empty.. Not working.. :( – Anish V Jan 30 '14 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.