Sharepoint - 字段在View / New Item上出现两次

时间:2009-06-10 08:14:29

标签: sharepoint sharepoint-2007 moss

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

5 个答案:

答案 0 :(得分:7)

我遇到了同样的问题,在列表定义中添加列后,它们开始在new / edit / view项表单中出现两次。我刚刚更改了列表设置中的列排序,问题就解决了。

答案 1 :(得分:5)

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

我使用的解决方案(至少与contenttypes一起使用)是将站点contenttypes上的fieldlinks与包含contenttype的实际xml文件(feature)中的fieldlinks进行比较。如果它们不是相同数量的fieldlinks ...采取措施删除重复项。

答案 2 :(得分:4)

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

MSDN Article

请注意以下文字

  

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

答案 3 :(得分:2)

使用此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()

答案 4 :(得分: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();

    }
}