SharePoint 品牌按主题更改 SiteLogoUrl,不存在主题应用事件
到目前为止,我们还不需要为 SharePoint 站点定义创建新的母版页。 我们有一个主题,一些客户将根据他们的公司 SharePoint 品牌使用该主题。
目前,我使用以下代码更改“FeatureReceiver”中“FeatureActivated”事件中的“SiteLogoUrl”。
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
AddThemeToSpThemes(THEME_ID, THEME_NAME, THEME_DESC, THEME_IMAGE, THEME_IMAGE);
SPWeb site = properties.Feature.Parent as SPWeb;
if (site != null) {
site.AllowUnsafeUpdates = true;
site.SiteLogoUrl = site.Url + "images/thLogo.gif";
site.Update();
}
}
FeatureActivated 不是触发的最佳事件,我更喜欢主题应用事件,但我似乎找不到。 也许我没有正确处理这个问题。
Up to this point we have not yet needed a new masterpage for our SharePoint Site Definition. We have a theme that some of our customers will use depending on their corporate SharePoint branding.
Currently I change the 'SiteLogoUrl' in my 'FeatureReceiver' on the 'FeatureActivated' event using the following code.
public override void FeatureActivated(SPFeatureReceiverProperties properties) {
AddThemeToSpThemes(THEME_ID, THEME_NAME, THEME_DESC, THEME_IMAGE, THEME_IMAGE);
SPWeb site = properties.Feature.Parent as SPWeb;
if (site != null) {
site.AllowUnsafeUpdates = true;
site.SiteLogoUrl = site.Url + "images/thLogo.gif";
site.Update();
}
}
FeatureActivated is not the best event to trigger on, I would prefer a theme applied event but I can't seem to find one. Perhaps I am not approaching this correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应用主题没有事件。
您可能会向后执行此操作(尽管是显而易见的方式)。 如何让您的功能接收器 激活以编程方式设置主题,以及设置徽标?
请注意,您可以将当前应用的主题存储在 SPWeb 的属性包中 - 请参阅 这是一个示例,但在更改之前存储当前母版页。
值得考虑使用 替代 CSS主题也。 也可以在 SPWeb 对象 (AlternateCssURL) 上进行设置。
Applying a theme doesn't have an event.
You may be doing this backwards (although the obvious way). How about having your feature receiver activate the theme programmatically, as well as setting your logo?
Note you can store the currently applied theme in the SPWeb's property bag - see this for an example, but storing the current master pages before changing them.
It is worth considering using the Alternate CSS instead of Themes too. That can also be set on you SPWeb object (AlternateCssURL).
你的代码应该可以正常工作。 您可以在FeatureActivated/FeatureDeactivating 方法中添加自定义代码。
出于好奇,您为什么认为您没有使用正确的事件? sharepoint 中的事件不多,主题功能也相当有限。 CSS 文件很大,但 .net 部分很小。
我的猜测是,即使主题发生变化,您也想强制使用 SiteLogoUrl(这样您的客户就可以为他们的网站选择一个时髦的主题,同时保留徽标)。
另外,母版页不是主题,所以我不确定您为什么说“到目前为止,我们还不需要为 SharePoint 网站定义创建新的母版页”。
干杯,
马特。
Your code should work just fine. The FeatureActivated/FeatureDeactivating methods are the places where you can add custom code.
Out of curiosity, why did you think that you're not using the correct event? There aren't too many events in sharepoint, and the theme functionality is quite limited. The CSS files are extensive, but the .net side is small.
My guess is that you want to force the SiteLogoUrl, even if the theme changes (so your customers could choose a funky theme for their site, while keeping the logo).
Also, a masterpage is not a theme, so I'm not sure why you said, "Up to this point we have not yet needed a new masterpage for our SharePoint Site Definition".
Cheers,
Matt.