Question

How to edit a column name in Sharepoint ?When O rename a column I can't get by the code to column name.

           if (properties.List.Title == "Wpisy")
       {
           SPList lstOtherList = properties.Web.Lists["Szczegoly"];
           SPListItem item = lstOtherList.AddItem();

           item["Kontrakt"] = properties.AfterProperties["Kontrakt1"];
           item["Pracownik"] = properties.AfterProperties["Pracownik1"];
           item["Dzien"] = properties.AfterProperties["DzienStart"];

           item.Update();
       }
       base.ItemAdding(properties);

I must change a name for columns, and this is works, but i don't want to always build a new list from the begining.

Was it helpful?

Solution

Every column in SharePoint has 3 names:

  • InternalName (just called Name in <Field> and <FieldRef> elements)
  • StaticName
  • DisplayName (called Title in SPField)

InternalName can't be changed after field has been created
StaticName can be changed through code
DisplayName can be changed through code/UI

When accessing data/fields you should always use ID (often from SPBuiltInFieldId), InternalName (often using GetFieldByInternalName and then ID, but also directly as when accessing AfterProperties) or StaticName (often using TryGetFieldByStaticName and then ID)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top