Tuesday, May 27, 2014

Sample code to insert items in Composed look list to create a new theme

Hello All,
To create a new theme listing in "change the look" gallery you can create a custom pallete.color file and deploy it to the theme gallery and back ground image and deploy this image to the image folder in layouts.
Now, Create a feature activation receiver and write below code. This piece of code will create a new  entry in Composed looks list in your site. That's all, after that you can your theme listed in change the look gallery.

public override void FeatureActivated(SPFeatureReceiverProperties properties)


{

     

          
SPWeb web = properties.Feature.Parent as SPWeb;

// SPList list = web.GetList("_catalogs/design");

SPList list =web.GetCatalog(SPListTemplateType.DesignCatalog);

SPListItem item = list.AddItem();

item["Title"] = "The Dark Night";

item["Name"] = "The Dark Night";

//item[new Guid("460F49F1-8CF8-4E2D-B38B-30CE8DA26F89")] = "TheDarkNight";

SPFieldUrlValue masterUrl = new SPFieldUrlValue();

//uncomment below line to deploy in root site

// masterUrl.Url = "/_catalogs/masterpage/seattle.master";

masterUrl.Url = "/sites/Branding/_catalogs/masterpage/seattle.master";

item["MasterPageUrl"] = masterUrl;




SPFieldUrlValue theemUrl = new SPFieldUrlValue();

//uncomment below line to deploy the thems in Root site

//theemUrl.Url = "/_catalogs/theme/15/palette_dk.spcolor";

theemUrl.Url = "/sites/Branding/_catalogs/theme/15/palette_dk.spcolor";

item["ThemeUrl"]=theemUrl;

SPFieldUrlValue imageUrl = new SPFieldUrlValue();

imageUrl.Url = "/_layouts/15/images/MyThemes/dk011.jpg";

item["ImageUrl"] = imageUrl;

item.Update();
//item["FontSchemUrl"] = "";

//item["DisplaOrder"] = "100";

}  

No comments:

Post a Comment