简体   繁体   中英

How do I add custom column to existing WSS list template

I need to use feature stapler to add some text columns to Posts list inside OOTB blog site definition. I plan not to use site columns, but only to add those columns to list (I don't use site columns because I have multiple site collections and there will be only one Posts list per site collection, so site columns are not very reusable in this case). My question is: How do I achieve this?

Perhaps you can create a feature that uses the object model from the feature receiver to add (and remove as appropriate) the columns to just the specific list when the feature is activated.

I would use the XML Schema approach for creating the columns in order to ensure the same GUID for each column. See

The best solution is to create a hidden custom action for Posts List. I'm posting a simplified version here

Elements.xml:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="XXXXXXXX"
   RegistrationType="List"
   RegistrationId="101"
   Rights="Open"
   Location="ViewToolbar"
   Sequence="110"
   Title="Hidden Settings Button"
   ControlAssembly="MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXX"
       ControlClass="MyLib.MyClass"
   />

    <FeatureSiteTemplateAssociation Id="XXXXXXX" TemplateName="YOUR_BLOG_SITE_TEMPLATE_NAME" />

MyClass.cs:

  [DefaultProperty("Text")]
  [ToolboxData("<{0}:MyClass runat=server></{0}:MyClass>")]
  public class MyClass : WebControl
  {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["Text"] = value;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            SPList list = SPContext.Current.List;
            if (list != null)
            {
                 list.Fields.Add(XXX, XXX, XXX);
                 list.Update();
            }    
        }    
   }

I cannot see what benefit I have from creating custom action for posts list. Both posts are helpful, but I'll probably create custom feature for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM