当前位置: 代码迷 >> SharePoint >> SharePoint 定做化 更改theme
  详细解决方案

SharePoint 定做化 更改theme

热度:514   发布时间:2016-05-02 06:51:29.0
SharePoint 定制化 更改theme

1.针对于SharePoint 2010

 a.用PowerPoint 画 theme template

  这里用的是PowerPoint 2013

如图所示 :打开PowerPoint ->Design ->Colors->Customize Colors...

               出现如下图,可针对自己想要的theme template color 进行自定义

  点击Save 保存template ,然后save as 这个template 文件后缀命名为thmx,这里取名为Test.thmx

b.打开 visual studio

  创建Module 

  1)在Module 里添加Test.thmx

  2)Elements.xml里面配置如下

  <?xml version="1.0" encoding="utf-8"?>

  <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="RubyTheme" Url="_catalogs/theme">
      <File Path="RubyTheme\Test.thmx" Url="Test.thmx" />
    </Module>
  </Elements>

c.创建feature 在EventReciver.cs添加代码如下(这里针对Web 级别的feature)

  在FeatureActivated方法里

  SPWeb web = properties.Feature.Parent as SPWeb;

   ThmxTheme theme = ThmxTheme.Open(web.Site, themeUrl);

     theme.ApplyTo(web, false);
     web.Update();

在FeatureDeactivating方法里

  SPWeb web = properties.Feature.Parent as SPWeb;

    ThmxTheme.RemoveThemeFromWeb(web, true);

2. 针对SharePoint 2013

 Sharepoint 2013将Theme分为fontscheme and colorpalette

 下面仅针对colorpalette更改进行叙述

 a. 创建module 命名为RubyTheme

  1)把Test.spcolor 添加到Module下(调试spcolor文件 用SharePoint Color Palette Tool)

 2)Elements.xml配置如下

   <?xml version="1.0" encoding="utf-8"?>
   <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="RubyTheme" Url="_catalogs/theme/15">
  <File Path="RubyTheme\test.spcolor" Url="test.spcolor" ReplaceContent="TRUE" Type="GhostableInLibrary" />
  </Module>
  </Elements>

b.创建feature 在EventReciver.cs添加代码如下

 在FeatureActivated方法里

   SPFile colorPaletteFile = web.GetFile("_catalogs/theme/15/Test.spcolor");

   SPTheme theme = SPTheme.Open("RubyNewTheme", colorPaletteFile);
   theme.ApplyTo(web, false);

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

  SPQuery q = new SPQuery();
  q.RowLimit = 1;
  q.Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>";
  q.ViewFields = "<FieldRef Name='DisplayOrder'/>";
  q.ViewFieldsOnly = true;

  SPListItemCollection currentItems = designGallery.GetItems(q);

 if (currentItems.Count == 1)
 {
 // Remove the old Current item.
  currentItems[0].Delete();
 }

 SPListItem currentItem = designGallery.AddItem();
 currentItem["Name"] = SPResource.GetString(CultureInfo.CurrentUICulture, Strings.DesignGalleryCurrentItemName);
 currentItem["Title"] = SPResource.GetString(CultureInfo.CurrentUICulture, Strings.DesignGalleryCurrentItemName);
 currentItem["MasterPageUrl"] = web.MasterUrl;
 currentItem["ThemeUrl"] = colorPaletteFile.ServerRelativeUrl;
 currentItem["DisplayOrder"] = 0;
 currentItem.Update();

在 FeatureDeactivating方法里

  SPFile colorpaletteFile = web.GetFile("_catalogs/theme/15/palette001.spcolor");

 SPTheme theme = SPTheme.Open("Office", colorpaletteFile);
 theme.ApplyTo(web, false);

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

  SPQuery q = new SPQuery();
  q.RowLimit = 1;
  q.Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>";
  q.ViewFields = "<FieldRef Name='DisplayOrder'/>";
  q.ViewFieldsOnly = true;

  SPListItemCollection currentItems = designGallery.GetItems(q);

 if (currentItems.Count == 1)
 {
 // Remove the old Current item.
  currentItems[0].Delete();
 }

 SPListItem currentItem = designGallery.AddItem();
 currentItem["Name"] = SPResource.GetString(CultureInfo.CurrentUICulture, Strings.DesignGalleryCurrentItemName);
 currentItem["Title"] = SPResource.GetString(CultureInfo.CurrentUICulture, Strings.DesignGalleryCurrentItemName);
 currentItem["MasterPageUrl"] = web.MasterUrl;
 currentItem["ThemeUrl"] = colorPaletteFile.ServerRelativeUrl;
 currentItem["DisplayOrder"] = 0;
 currentItem.Update();

3.参考文献

 MSDN:Deploy a custom theme in SharePoint 2013

 

1楼一_叶知秋
写得非常好,受教了。
  相关解决方案