Web 部件“元数据”?

发布于 2024-08-02 03:43:18 字数 306 浏览 2 评论 0原文

我以前没有使用过用于共享点的 Web 部件,但需要对 Web 部件进行更改,需要将其传播到大约 700 个网站。 它是对webpart的属性之一的更改,需要更改该值。 有没有办法获取 Web 部件的元数据并直接在数据库中更改它(我假设这是存储它的位置。)?

以下是场景:Web 部件包含应显示的以逗号分隔的文档类型(内部类型)列表。 现在有新的文档。 需要添加到所有 700 个网站的类型。 我需要一种方法来枚举网站、获取 Web 部件元数据并将这些新文档类型添加到 Web 部件。 目前,他们手动访问每个网站,单击“编辑”,输入新的文档类型,然后保存。

I have not worked with webparts for sharepoint before, but need to make change to a webpart, that needs to be propagated to some 700 websites. It is a change to one of the properties of the webpart, the value needs to be changed. Is there a way to get metadata for a webpart and change it directly in the database (I assume that is where it is stored.)?

Here is the scenario: Webpart contains a comma delimited list of document types (internal type) that it should display. Now there are new doc. types that need to be added to all 700 websites. I need a way to enumerate websites, get the webpart metadata, and add these new doc types to webpart. Currently they go manually to each website, click on edit, type in new doc type, and save it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

∞觅青森が 2024-08-09 03:43:18

正如其他人所说,正确的方法是以编程方式实现这一点,而不是编辑内容数据库,这将使您的安装不受支持。 我经常使用控制台应用程序在由网站模板创建的网站组成的网站集中执行此操作。

下面是更改 ListViewWebPart 的 Title 属性的示例。 更新为包含递归循环的代码。 我还没有测试过这个,但它应该可以工作。

private static void ProcessSiteCollection(string url)
{
    using (SPSite siteCollection = new SPSite(url))
    {
        SPWeb rootWeb = siteCollection.RootWeb;
        ProcessWebs(rootWeb);
    }
}

private static void ProcessWebs(SPWeb parentWeb)
{
    foreach (SPWeb web in parentWeb.Webs)
    {
        try
        {
            UpdateWebPart(web); // Set web part properties
            ProcessWebs(web);   // Recursively loop through children
        }
        finally
        {
            web.Dispose();
        }
    }
}

private static void UpdateWebPart(SPWeb web)
{
    using (SPLimitedWebPartManager webPartManager =
        web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared))
    {
        try
        {
            foreach (WebPart webPart in webPartManager.WebParts)
            {
                    if (webPart.Title == "My Web Part")
                    {
                            ListViewWebPart listViewWebPart = (ListViewWebPart)webPart;
                            listViewWebPart.Title = "Updated Web Part";
                            webPartManager.SaveChanges(listViewWebPart);
                            web.Update();
                            break;
                    }
            }
        }
        finally
        {
            webPartManager.Web.Dispose();
        }
    }
}

As others have said the correct approach is to programmatically achieve this rather than edit the content database which will make your installation unsupportable. I regularly use a console application to do this in a site collection made up of sites created from a site template.

Here is an example that changes the Title property of a ListViewWebPart. Updated to include code for recursive loop. I haven't tested this but it should work.

private static void ProcessSiteCollection(string url)
{
    using (SPSite siteCollection = new SPSite(url))
    {
        SPWeb rootWeb = siteCollection.RootWeb;
        ProcessWebs(rootWeb);
    }
}

private static void ProcessWebs(SPWeb parentWeb)
{
    foreach (SPWeb web in parentWeb.Webs)
    {
        try
        {
            UpdateWebPart(web); // Set web part properties
            ProcessWebs(web);   // Recursively loop through children
        }
        finally
        {
            web.Dispose();
        }
    }
}

private static void UpdateWebPart(SPWeb web)
{
    using (SPLimitedWebPartManager webPartManager =
        web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared))
    {
        try
        {
            foreach (WebPart webPart in webPartManager.WebParts)
            {
                    if (webPart.Title == "My Web Part")
                    {
                            ListViewWebPart listViewWebPart = (ListViewWebPart)webPart;
                            listViewWebPart.Title = "Updated Web Part";
                            webPartManager.SaveChanges(listViewWebPart);
                            web.Update();
                            break;
                    }
            }
        }
        finally
        {
            webPartManager.Web.Dispose();
        }
    }
}
ゝ杯具 2024-08-09 03:43:18

直接访问共享点内容数据库是一个很大的“禁忌”。 这就是官方的答案。 :)

话虽这么说,我只查看过内容数据库,从未尝试过手动实际更改任何内容。

我的建议是修改现有的 Web 部件,以根据当前设置的属性修改属性。 (我假设当前设置的某些属性无效或需要根据基础设施的更改进行更新。)...如果是这种情况,您可以验证该属性; 确保当前属性更改为所需的属性,和/或确保将来的属性更改有效。

祝你好运!

Directly accessing the sharepoint content databases is a big "no no." That's the official answer. :)

That being said, I have only ever looked in the content databases and never tried to actually change anything manually.

My suggestion, would be to modify the existing web part to modify the property based on currently set property(s). (I am assuming that some currently set property is invalid or needs to be updated based on changes to the infrastructure.) ... If this is the case, you can validate the property; making sure that current property is changed to what it needs to be, and/or making sure future property changes are valid.

Good luck!

夜唯美灬不弃 2024-08-09 03:43:18

不要

说真的,不要进入内容数据库并对其进行编辑。 这样,如果发生任何情况,您将不再受到支持,并且 Microsoft 将不再支持您(除非您将数据库从备份恢复到早期版本)。

您可以使用 API 访问网站中的 Web 部件,以下是一些可以帮助您入门的代码:

枚举页面 Web 部件

DON'T

Seriously, do not go into the content databases and edit it. That way you are not supported anymore if anything should happen and Microsoft will not support you anymore (not until you revert the database back to an earlier version from a backup that is).

You can use the API to access webparts in your sites, here's some code that should get you started:

Enumerate page webparts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文