简体   繁体   English

SharePoint 2007-更新所有网站主页

[英]SharePoint 2007 - Update all site home pages

I am wondering if there is a way to update all site home pages to display a new custom web part. 我想知道是否有一种方法可以更新所有站点主页以显示新的自定义Web部件。

I have a site collection with 100+ sub sites and I have created a custom web part which i want to display in all site home pages.. what would you suggest as the best way to do this, as as doing this manually will take considerable time?! 我有一个包含100多个子网站的网站集,并且我创建了一个自定义Web部件,该部件要显示在所有网站首页中。您建议这样做的最佳方法是什么,因为手动执行此操作会花费大量时间时间?!

First write the code to programmatically add a webpart to a single homepage. 首先,编写代码以编程方式将Webpart添加到单个主页。 The specifics of how to do this will vary based on how your homepage is structured, whether it's a publishing page, etc. It's most likely possible, but implementations could differ. 具体操作方法将根据您首页的结构,是否为发布页面等而有所不同。这很有可能,但是实现方式可能会有所不同。 You'll possibly be using something similar to this: 您可能会使用与此类似的东西:

using(SPSite site = new SPSite("http://localhost"))
using(SPWeb web = site.RootWeb)
{
    web.AllowUnsafeUpdates = true;
    SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("Pagees/Home.aspx"
        , System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

    MyWebPart wp = new MyWebPart();      // your custom webpart
    wp.Title = "My WebPart";

    webParts.AddWebPart(wp, "Left", 0);
    webParts.SaveChanges(wp);
}

There are lots of variations when searching the subject online. 在线搜索主题时,会有很多变化。

Once you have that you can create either a console application or a feature to be executed on the top level site, open up each subsite, and then execute the above code. 一旦有了,就可以创建控制台应用程序或要在顶级站点上执行的功能,打开每个子站点,然后执行上面的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM