views:

29

answers:

1

Hi,

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!

A: 

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.

Rich Bennema
Thanks for the help! I've been re-tasked to something else for a bit, but will be sure to look into this when I get back to SharePoint, and say how it goes.
James