简体   繁体   中英

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 new 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 .

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