Wednesday, January 14, 2009

Programatically deleting fields from List

Scenario:
You want to delete a corrupted field from a particular list.

Solution:
Object Model can help, also code can be extended to multiple site collection , webs ,lists or fields.
Code:

           using (SPSite oSiteCollection = new SPSite("http://localhost"))
{
using (SPWeb oWebsite = oSiteCollection.RootWeb)
{
SPList list = oWebsite.Lists["Shared Documents"];
list.Fields["Test"].Delete();
list.Update();
}
}

0 comments: