使用内容数据库更新内部名称

发布于 2024-09-24 17:17:59 字数 181 浏览 5 评论 0原文

目前,我们有一个字段的 ID 错误。 Sharepoint 字段的 ID 和内部名称在域模型上是只读的。我想知道是否有办法甚至通过使用内容数据库来更新它们。

一种可靠的方法是删除该字段并重新创建它。但它已经有数据了,而且有数千页。我想知道是否有一种方法可以只更新 ID 和内部名称,而不需要删除和重新创建字段。

谢谢

We currently have a field which has the wrong ID. the IDs and Internal Names of Sharepoint Fields are readonly on the domain model. I was wondering if there is a way to update them even by using the content database.

One sure way is to delete the field and recreate it. but it already has data and there are thousands of pages. I was wondering if there is a way just to update the IDs and Internal Name without doing the dropping and recreation of fields.

Thanks

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

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

发布评论

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

评论(3

尾戒 2024-10-01 17:17:59

即使它可能有效,也不要这样做。
它是:

  • 危险,因为您可能会跳过依赖项
  • 不支持

使用某些脚本重新创建字段来保存数据更安全。

Even if it may work, don't do it.
It's:

  • Dangerous, as you may skip dependencies
  • Not supported

Recreating the field using some script to keep data is safer.

新人笑 2024-10-01 17:17:59

我们遇到了同样的问题。搞乱数据库对我们来说不是一个选择(也不应该适合您),但您可以解决它。不幸的是,需要触摸每个页面才能更新元数据。

首先,创建列,就像它应该在列表中一样。然后,您可以通过多种方式将数据从旧列复制到新列:

  1. 数据表视图
  2. 通过 Web 服务以编程方式(不需要访问服务器)
  3. 通过控制台应用程序以编程方式(需要在本地运行)服务器)

老实说,编写一个小型控制台应用程序将是最快的。例如:

string siteUrl = "http://server/sitecollection/";
string webUrl = "subsite1/subsite2/";
string listName = "Your List Name";
using (SPSite site = new SPSite(siteUrl))
{
    using (SPWeb web = site.OpenWeb(webUrl))
    {
        SPList list = web.Lists[listName];
        foreach (SPListItem item in list.Items)
        {
            item["New_x0020_Column_x0020_Name"] = item["Old_x0020_Column_x0020_Name"];
        }
    }
}

此外,强烈建议首先在开发环境中尝试此操作。只需从生产环境执行 STSADM 恢复并测试您的控制台应用程序即可。然后,验证您的数据并删除旧列!

We ran into the same problem. Messing with the DB was not an option for us (and shouldn't be for you either), but you can work around it. Unfortunately, it will require touching each page to update the metadata.

First, create the column like it should be in the list. Then, you can copy the data from the old column to the new column in a variety of ways:

  1. DataSheet view
  2. Programmatically via web services (don't need to have access to the server)
  3. Programmatically via console app (will need to run locally on the server)

Honestly, writing a small console app will be the quickest. For example:

string siteUrl = "http://server/sitecollection/";
string webUrl = "subsite1/subsite2/";
string listName = "Your List Name";
using (SPSite site = new SPSite(siteUrl))
{
    using (SPWeb web = site.OpenWeb(webUrl))
    {
        SPList list = web.Lists[listName];
        foreach (SPListItem item in list.Items)
        {
            item["New_x0020_Column_x0020_Name"] = item["Old_x0020_Column_x0020_Name"];
        }
    }
}

Also, it would HIGHLY recommend trying this in a DEV environment first. Just do an STSADM restore from your production environment and test your console app. Then, validate your data and delete the old column!

人事已非 2024-10-01 17:17:59

我不建议修改内容数据库,因为它是:

  • 不受支持(如果你这样做,即使你有 MS Premier 支持,当你遇到真正的麻烦时,微软也不会帮助你)
  • 做起来非常复杂。您必须更新许多表,并且您永远无法确定是否确实更新了所有必需的内容。

您可以尝试做什么 - 查看内部名称属性实际上是“只读”还是被定义为“朋友”,并且您无法从不同的代码程序集中调用它。如果是后一种情况,您可以使用.Net反射来设置属性值。有关详细信息,请参阅此 MSDN 文档链接

I would not suggest modifying the content database, since it is:

  • unsupported (if you do it, Microsoft will not help you when you're in real trouble even if you have MS Premier Support)
  • very complicated to do. You'd have to update a number of tables and you would never be sure if you actually updated all the required things.

What you can try to do - see if the internal name property is actually "read only" or it is defined as "friend" and you cannot call it from a different code assembly. If it's the latter case, you can use .Net reflection to set the property value. See this MSDN documentation link for details.

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