Wednesday, June 17, 2015

How to update properties of existing Custom Site Column in C#



Some time you may require to update property of existing custom site column like need to convert type of column or many thing can be possible, there are many way to do the same, see the simplest way to do pro grammatically in C#.
Just you need to write simple line of Code, you will see the change after executing the below code.
using (SPSite site = new SPSite(“http://SPSite:50003;))
{
using (SPWeb web = site.OpenWeb())
{
SPField fa = web.Fields[“Document Approver”];
fa.SchemaXml = fa.SchemaXml.Replace(“<Field”, “<Field List=\”UserInfo\” “);
fa.PushChangesToLists = true;
fa.Update();
}
}
There is an custom field with User type named “Document Approver”, the above code is adding one property “List=UserInfo”.
Before updation the schema xml of custom field,
<Field ID=”{b81d6548-115e-43b8-8745-e7ba162c893c}” Type=”User” Name=”Document_Approver”
StaticName=”Document_Approver” DisplayName=”Document Approver”
Required=”FALSE” Group=”custom” SourceID=”{1a517130-6e88-4412-ae5e-b79c6b6b1f32}” Version=”2″ />
After updation of schema xml of custom field,
<Field List=”UserInfo” ID=”{b81d6548-115e-43b8-8745-e7ba162c893c}” Type=”User” Name=”Document_Approver”
StaticName=”Document_Approver” DisplayName=”Document Approver”
Required=”FALSE” Group=”custom” SourceID=”{1a517130-6e88-4412-ae5e-b79c6b6b1f32}” Version=”2″ />

No comments:

Post a Comment