Add Custom Column Choice to sharepoint List

No.of Views1653
Bookmarked0 times
Downloads 
Votes0
By  André Lage   On  15 Jul 2010 08:07:02
Tag : SharePoint , Development and Programming
this code help you create custom column on List.Create a custom field call Choice Year years and multiple choice and add to List.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

this code help you create custom column on List.Create a custom field call Choice Year years and multiple choice and add to List.

Codesnippet

using (SPSite site = new SPSite ("Site Path"))
(
using (SPWeb web = site.OpenWeb ())
(
/ / Validate Field is exist 
if (! web.Lists ["Shared Documents"]. Fields.ContainsField ("Year")) 
( 

SPField customField; 
/ / Creating a new field 
MyField web.Fields.CreateNewField = (SPFieldType.Choice.ToString (), "Year");
/ / Required the Field 
MyField.Required = true;
Web.Lists SPList list = ["Shared Documents"];
SPField Year = MyField;
list.Fields.Add (Year);

SPFieldChoice YearField = (SPFieldChoice) list.Fields ["Year"];
for (int i = 1990; i <2021; i + +)
(
YearField.Choices.Add (i.ToString ()); 
)
YearField.DefaultValue DateTime.Now.Date.Year.ToString = ();
YearField.Update (); 
)
)
)

Hope you like.

 
Sign Up to vote for this article
 
About Author
 
André Lage
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Portugal
Joined date-09 Jun 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top