Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Delete Content Types in Asset Library Programmatically in Sharepoint 2010

Delete Content Types in Asset Library Programmatically in Sharepoint 2010

A quick tip on how to delete the default content types in Asset library and adding your own custom content type using SharePoint 2010 object model. The default content types included with the AssetLibrary definition are Audio, video and Image.

SPSite oSite = new SPSite(“http://blrs2r8-11″);

SPWeb oWeb = oSite.OpenWeb();

SPListTemplate Otemplate = oWeb.ListTemplates["Asset Library"];

SPList oList = oWeb.Lists[oWeb.Lists.Add("NewList", "New List from Code", Otemplate)];

oList.ContentTypes["Video"].Delete();

oList.ContentTypes["Audio"].Delete();

oList.ContentTypes["Image"].Delete();

SPContentType oCtype = oWeb.ContentTypes["Custom Content Type"];

oList.ContentTypes.Add(oCtype);

oList.Update();

No comments:

Post a Comment