【问题标题】:Sharepoint - Field appears twice on View / New ItemSharepoint - 字段在视图/新项目上出现两次
【发布时间】:2009-06-10 08:14:28
【问题描述】:

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

【问题讨论】:

    标签: sharepoint sharepoint-2007 moss


    【解决方案1】:

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

    【讨论】:

    • 有趣的解决方法,谢谢。我实际上知道 SharePoint 中有几个问题可以通过这些问题来解决...
    【解决方案2】:

    是的,我在处理添加到列表的内容类型时遇到了这些问题。当我以某种方式对内容类型进行更新时,有时会出现重复。当我查看它们时,它们似乎是相同的 ID 和名称,但实际上 ID 不同。

    我使用的解决方案(至少适用于内容类型)是将站点内容类型上的字段链接与包含该内容类型的实际 xml 文件(功能)中的字段链接进行比较。如果它们不是相同数量的字段链接...采取措施删除重复项。

    【讨论】:

    • 你好约翰,谢谢!顺便说一句,您是绝对正确的,这是通过功能添加到列表中的内容类型(虽然不是我的)。我在哪里可以找到这些字段链接?是否以编程方式完成?
    • 我的意思是 如果你认识他们的话。指向内容类型中使用的字段的链接。由于您无法访问实际功能,因此在这种情况下,我会推荐 Colin 的解决方案。我的解决方案并没有得到真正的支持,但无论如何......在 SharePoint 中,我们无论如何都需要克服障碍...... :-)
    【解决方案3】:

    更新创建内容类型的 xml 是不明智的。如果您想稍后将字段添加到内容类型,请通过新功能来完成,请参阅此链接。

    MSDN Article

    注意以下文字

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

    【讨论】:

    • 生产中存在问题,我们有真实数据。我们创建了新列并将数据复制到它们,并删除了重复的列。所以,在某种程度上,你的解决方案就是我们所做的——什么都没有。 :-)
    【解决方案4】:

    使用此 powershell 脚本清除重复项:

    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()
    

    【讨论】:

      【解决方案5】:

      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();
      
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2012-08-18
        • 1970-01-01
        • 2016-02-17
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多