【问题标题】:How to modify internalname in Sharepoint 2010 list field如何修改 Sharepoint 2010 列表字段中的内部名称
【发布时间】:2014-07-07 10:48:30
【问题描述】:

我需要更改 sharepoint 2010 列表项字段的内部名称。由于某种原因,我们的迁移软件在 2007->2010 迁移期间对其进行了重命名,并且该字段被其他进程引用,因此我们需要将内部名称恢复为原始名称。该字段存在于已迁移站点的 200 多个列表中,因此我们需要一种以编程方式执行此操作的方法 - 首选 powershell。

【问题讨论】:

    标签: powershell sharepoint-2010 sharepoint-list


    【解决方案1】:
    $newInternalName = "yourInternalFieldName"
    $displayName = "oldDisplayName"
    $SPWebApp = Get-SPWebApplication "http://yourwebapp"
    
    foreach (SPList $currList in $SPWebApp.Lists)
    {
        foreach (SPField $fld in $currList.Fields) #you could potentially use a different command here to get the field more efficiently
        {
            if ($fld.Name == $displayName)
            {               
                #The boolean in the parameter list is for required/non-required field $currList.Fields.Add($newInternalName,Microsoft.SharePoint.SPFieldType.Text,$False)
                foreach (SPListItem $item in $currList.Items)
                {
                    $item[$newInternalName] = $item[$displayName] 
                    $item[$newInternalName].Title = $displayName #I'm assuming you want to keep the display name the same
                        $item.Update()
                }
                Break #since you've already fixed the column for this list no need to keep going through the fields
                # optional delete unwanted column
                # $currList.Fields.Delete($displayName)
                # $currList.Update()
            }
        }
    }
    

    据我所知,一旦创建字段,您就无法更改其内部名称。在这里,我创建了一个具有正确内部名称的新字段并复制了这些值。我今天无法使用 Powershell 访问服务器,因此无法对此进行测试,但这应该非常接近您的需要。如果您想使用不同的 Add 函数和/或想要删除旧字段,您可能需要根据您正在处理的字段类型对其进行一些调整。

    这里定义了Add函数中选择字段类型的枚举: http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.spfieldtype(v=office.14).aspx

    Add 函数有几个重载,所以如果我使用的那个不适合你,你可能想使用其中一个 http://msdn.microsoft.com/en-us/library/office/aa540133(v=office.14).aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 2012-08-14
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      相关资源
      最近更新 更多