Welcome to MSDN Blogs Sign in | Join | Help
ADD SPFieldType.Choice, SPFieldChoice with SPChoiceFormatType.RadioButtons
using Microsoft.SharePoint;
using System.Collections.Specialized;
 
public void OnActivated(SPFeatureReceiverProperties properties)
{
    SPWeb web = (SPWeb)properties.Feature.Parent;
    string url = new Uri(web.Url).AbsolutePath;
 
    SPDocumentLibrary docLib = (SPDocumentLibrary)web.GetListFromUrl("Shared Documents/Forms/AllItems.aspx");
 
    // Create collection with choices.
    StringCollection categories = new StringCollection();
    categories.AddRange(new string [] {"Choice A", "Choice B", "Choice C"} );
 
    // Create new field in the project documents list.
    docLib.Fields.Add("MyNewField", SPFieldType.Choice, true, false, categories);
 
    // Set additional settings of the new field.
    SPFieldChoice fieldChoice = (SPFieldChoice)docLib.Fields["MyNewField"];
    fieldChoice.DefaultValue = "Choice A";
    fieldChoice.EditFormat = SPChoiceFormatType.RadioButtons;
 
    // Save settings.
    fieldChoice.Update();
    docLib.Update();
}
Posted: Friday, June 06, 2008 8:35 PM by itsmeskv

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker