2009-06-10 84 views
5

我在SharePoint列表中出现问题 - 某些字段在显示窗体,新建项目窗体和列表设置页面上显示两次。这两个字段具有相同的ID和相同的属性页面(相同的URL),因此隐藏一个隐藏另一个。
使用SharePoint Manager我只能看到一个字段,但也许我看了错误的地方? 有没有人经历过类似的事情,我该如何解决这个问题?Sharepoint - 字段在查看/新项目上出现两次

回答

4

更新创建内容类型的xml并不明智。如果您想稍后添加字段到内容类型,请通过新功能执行此操作,请参阅此链接。

MSDN Article

请注意下面的文本

在任何情况下,你应该更新的内容类型的内容类型定义文件已安装并激活该内容类型之后。 Windows SharePoint Services不会跟踪对内容类型定义文件所做的更改。因此,您没有办法将对站点内容类型所做的更改推送到子内容类型。 有关更改已安装和激活的内容类型时的最佳做法的信息,请参阅更新内容类型。

+0

生产中存在的问题,我们有真实的数据。我们创建了新列并将数据复制到它们,并删除了重复的列。所以,从某种意义上说,您的解决方案就是我们所做的 - 什么都不是:-) – Kobi 2009-06-11 08:12:43

5

Yepp,我已经遇到了将这些内容类型添加到列表中的问题。当我以某种方式更新内容类型时,我有时会得到重复的内容。当我看着他们,他们似乎是相同的ID和名字,但ID实际上是不同的。

我用过的解决方案(至少与contenttypes一起使用)是将网站contenttypes上的字段链接与包含contenttype的实际xml文件(feature)中的字段链接进行比较。如果它们的字段链接数不相同...请执行操作以删除重复项。

+0

Hello Johan,谢谢!你是绝对正确的,顺便说一句,这是一个内容类型添加到列表的功能(不是我的,但)。我在哪里可以找到这些fieldlinks?它是否以编程方式完成? – Kobi 2009-06-10 08:45:25

+0

我的意思是如果你知道他们。链接到contenttype中使用的字段。由于您无法访问实际功能,因此我会在这种情况下推荐Colin的解决方案。我的解决方案没有得到真正的支持,但无论如何......在SharePoint中,我们需要绕过障碍,无论如何我们可以...... :-) – 2009-06-10 20:12:47

7

我得到了同样的问题,在列表定义中添加列后,他们开始出现在新/编辑/查看项目形式两次。我只是改变了列表设置的列顺序,问题解决了。

+2

有趣的解决方法,谢谢。我实际上知道SharePoint中的几个问题可以通过完全解决...... – Kobi 2011-08-22 14:37:42

2

使用此PowerShell脚本来清​​洁dublicates:

Clear-Host 
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue 
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") 

$web=Get-SPWeb "http://weburl.here" 

function cleanFieldLinks($listName){ 
    $list = $web.GetList($listName) 
    $ct = $list.ContentTypes[0]; 

    $flDub = $ct.FieldLinks | group-object DisplayName | where { $_.Count -gt 1 } 

    foreach($fl in $flDub) { 
     $skipFirst = $fl.Group | select-object -skip 1 

     foreach($flDel in $skipFirst){ 
      $ct.FieldLinks.Delete($flDel.Id) 
     } 
    } 
    $ct.Update() 

} 

cleanFieldLinks("lists/listurl") 
$web.Dispose() 
2

1)首先,我想提一提,我碰到这个问题,因为我是对我做MOSS 2007的解决方案包MOSS 2013年MOSS兼容工作2013似乎不喜欢重复的字段名称。因此,如果您的自定义字段具有与MOSS 2013一起提供的字段相同的名称,则会发现重复的字段名称被发现错误。

2)这迫使我不得不返回并更新我的自定义字段和内容类型。在对造成重复字段名称问题的自定义字段进行更改后,我发现我的字段名称多次出现的问题。

3)我写了一个web表单页面来解决在视图,新建和编辑表单上多次显示该字段的问题。你只需要修改代码来指定你想要检查的列表。此版本将删除fieldref的第一个实例并保留第二个实例:

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
//using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
//using System.Xml.Linq; 

using Microsoft.SharePoint; 

using System.Text; 
using System.Collections.Generic; 



public partial class FixDuplicateFieldIssue : Microsoft.SharePoint.WebControls.LayoutsPageBase 
{ 



    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (SPContext.Current.Web.CurrentUser == null) 
     { 
      Response.Write("You must be logged in to view this page."); 
      Response.End(); 
      return; 

     } 
     if (!SPContext.Current.Web.DoesUserHavePermissions(SPBasePermissions.ManageWeb)) 
     { 
      Response.Write("You do not have permissions to view this page."); 
      Response.End(); 
      return; 
     } 

     lblOutput.Text = ""; 

     StringBuilder sbOutput = new StringBuilder(); 

     using (SPSite site = new SPSite(SPContext.Current.Site.ID)) 
     { 
      using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) 
      { 
       try 
       {  
        hlBack.NavigateUrl = web.Url; 

        //open the List **** SPECIFY THE LISTNAME HERE *** 
        SPList spList = web.Lists["LISTNAME"]; 
        if (spList != null) 
        { 
         //Check FieldLinks 

         sbOutput.Append("<table border='1'>"); 

         foreach (SPContentType ct in spList.ContentTypes) 
         { 
          sbOutput.Append("<tr>"); 
          sbOutput.Append("<td>" + ct.Name + "</td>"); 
          sbOutput.Append("<td>"); 

          Dictionary<string, Guid> GuidDictionary = new Dictionary<String, Guid>(); 
          List<Guid> RepeatList = new List<Guid>(); 
          //SEARCH THE CONTENT TYPE FOR REPEAT SPFieldLinks 
          foreach (SPFieldLink spfl in ct.FieldLinks) 
          { 
           if (!GuidDictionary.ContainsKey(spfl.Name.ToLower())) 
           { 
            GuidDictionary.Add(spfl.Name.ToLower(), spfl.Id); 
           } 
           else if (GuidDictionary[spfl.Name.ToLower()].ToString().ToLower()!=spfl.Id.ToString().ToLower()) 
           { 
            //Record the GUID of the repeat SPFieldLink you want to delete in the RepeatList. In this case, we're recording the first item. If you want to delete the second one, add the spfl.Id instead. 
            RepeatList.Add(GuidDictionary[spfl.Name.ToLower()]); 
            sbOutput.Append("<span style='color:red;'>*</span>"); 
           } 

           sbOutput.Append(spfl.Name + "," + spfl.Id + "," + spfl.DisplayName +"<br />"); 

          } 
          sbOutput.Append("</td>"); 

          sbOutput.Append("<td>"); 
          sbOutput.Append("Repeats found: " + RepeatList.Count + "<br />"); 

          //DELETE THE Repeat Field Links 
          foreach (Guid idToDelete in RepeatList) 
          { 

           sbOutput.Append("Deleting FieldRef with ID= " + idToDelete.ToString() + "<br />"); 
           web.AllowUnsafeUpdates = true; 
           ct.FieldLinks.Delete(idToDelete); 
           ct.Update(); 
           web.AllowUnsafeUpdates = false; 

          } 
          sbOutput.Append("</td>"); 




          sbOutput.Append("</tr>"); 
         } 
         sbOutput.Append("</table>"); 





        } 
       } 
       catch (Exception ex) 
       { 
        sbOutput.Append("Error Occurred: " + ex.ToString()); 
       } 

      } 
     } 
     lblOutput.Text = sbOutput.ToString(); 

    } 
}