views:

287

answers:

1

I need help creating a method that allows me to create a bunch of fields during featureactivated. C#. There are about 15 different fields, of varying types, and I'd like to be able to pass in all of the necessary attributes to create each field.

Anyone have any sample code or guidance on this?

A: 

Okay I found part of the answer...quite a bit to go though. I found the following utility method here:

public void AddCustomField(SPWeb web, string fieldType, string fieldName, bool isRequired, string defaultValue, string fieldGroup)
    {            
        //Check if the field is there or not already            
        if (!web.Fields.ContainsField(fieldName))            
        {                
            //Initializing a SPField instance                
            SPField customField;                
            //Creating a new filed                
            customField = web.Fields.CreateNewField(fieldType, fieldName);                
            //Assigning a group                
            customField.Group = fieldGroup;                
            //Sets this field is required field                
            customField.Required = isRequired;                
            //Assigning a default value                
            customField.DefaultValue = defaultValue;                
            //Adding the newly created field to SPweb                
            web.Fields.Add(customField);            
        }        
    }

However, I'm not sure how to call this method, could someone give me an example?

PushCode