开发者

How Can I Add a New Column to All Document Library Lists in SharePoint 2010 Using Visual Studio 2010?

I can't figure out how to create a solution in Visual Studio 2010 that will allow me to alter existing lists in a SharePoint 2010 site. Specifically, I want to add a new column, which contains a small icon, to existing document library lists. I want to be able to take an action when someone clicks on one of the new icons. I also want this new column to become part of the default view for ne开发者_JS百科w document library lists. All of this needs to be easily deployed to a SharePoint 2010 site via a .wsp file.

Extensive searching on Google has shown how to create new lists and new column types, and how to programmatically add columns to one of the new lists, but not how to modify all existing lists.

I'm brand new to SharePoint, and any pointers towards a solution would be much appreciated. Thanks!


If you really want to change all Document Libraries in the site, you could try changing the Content Type:

using (SPSite site = new SPSite("http://localhost"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPContentType ct = web.ContentTypes[SPBuiltInContentTypeId.Document];
        SPField fld = web.Fields.GetField(fldName);
        SPFieldLink lnk = new SPFieldLink(fld);
        ct.FieldLinks.Add(lnk);
        ct.Update(true);
    }
}

The above code is shortened and modified from the example of SPContentType.Update Method (Boolean). The MSDN article also has good general information on Updating Content Types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜