如何在 SharePoint 2010 EditModePanel 中显示正确的分类控件?

发布于 2024-10-17 02:39:56 字数 2149 浏览 2 评论 0原文

我们的 SharePoint 2010 版本中有一个自定义内容类型,其中包括关键字的托管元数据字段。

该字段似乎已部署正常,因为如果我编辑它所在的列表中的项目,我会获得正确的分类选择器控件,并且我的术语会从术语库中检索。

然而;我们在项目的 PageLayout 上使用 EditModePanel 来允许对项目进行现场编辑,但我无法显示正确的分类选择器控件。

如果我将 TaxonomyWebTaggingControl 添加到页面布局并对 SSPId 等进行硬编码,那么它就可以工作;

<TaxonomyControls:TaxonomyWebTaggingControl runat="server" SSPId="234234-234234-34341-343" TermSetId="234234-23342-34234-234-234"/>

但是,我们无法对这些值进行硬编码,因为术语库将在客户端部署站点时创建。

当我们创建内容类型时,我们有一个事件接收器,它使用名称将字段绑定到正确的术语存储/集,但我不明白如何在 EditModePanel 中获取字段来获取/设置这些字段。

我真正想要的是:

<TaxonomyControls:TaxonomyWebTaggingControl runat="server" TermStore="My term store name" TermSet="Keywords"/>

我错过了什么吗?

我的事件接收器如下所示:

 try
        {
            SPSite site = ((SPWeb)properties.Feature.Parent).Site as SPSite;

            Guid fieldId = new Guid("3211B052-5332-424C-A066-BBE21AEAB878");
            if (site.RootWeb.Fields.Contains(fieldId))
            {
                TaxonomySession session = new TaxonomySession(site);

                if (session.TermStores.Count != 0)
                {
                    var termStore = session.TermStores["Managed Metadata Service"];
                    var group = termStore.Groups.GetByName("My Client");
                    var termSet = group.TermSets["Keywords"];

                    TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;

                    field.SspId = termSet.TermStore.Id;
                    field.TermSetId = termSet.Id;
                    field.AnchorId = Guid.Empty;
                    field.AllowMultipleValues = true;
                    field.TextField = fieldId;
                    field.TextField = new Guid("{574C5BCE-74E8-40C8-BE90-C9338135D491}");
                    field.Update();
                    Log.Logger.LogEvent("ContentType Activation", "Updated keywords field with MMS details");
                }
            }
        }
        catch (Exception ex)
        {
            Log.Logger.LogException(ex, "Content Type Activation", ex.Message);
        }

We have a custom content type in our SharePoint 2010 build which includes a Managed Metadata field for keywords.

The field seems to have deployed OK because if I edit an item in the list in which it resides I get the correct Taxonomy picker control and my terms are retrieved from the term store.

However; we are using an EditModePanel on the PageLayout for the item to allow in-site editing of the items and I can't get the correct Taxonomy picker control to appear.

If I add a TaxonomyWebTaggingControl to the page layout and hardcode the SSPId etc then it works;

<TaxonomyControls:TaxonomyWebTaggingControl runat="server" SSPId="234234-234234-34341-343" TermSetId="234234-23342-34234-234-234"/>

However we can't hardcode the values as the term store will be created when the client deploys the site.

When we create the Content type we have an Event Receiver which binds the field to the correct Term Store/Set using their names but I don't understand how to get a field in the EditModePanel to get/set these.

What I really want is something like:

<TaxonomyControls:TaxonomyWebTaggingControl runat="server" TermStore="My term store name" TermSet="Keywords"/>

Am I missing something?

My event receiver looks like this:

 try
        {
            SPSite site = ((SPWeb)properties.Feature.Parent).Site as SPSite;

            Guid fieldId = new Guid("3211B052-5332-424C-A066-BBE21AEAB878");
            if (site.RootWeb.Fields.Contains(fieldId))
            {
                TaxonomySession session = new TaxonomySession(site);

                if (session.TermStores.Count != 0)
                {
                    var termStore = session.TermStores["Managed Metadata Service"];
                    var group = termStore.Groups.GetByName("My Client");
                    var termSet = group.TermSets["Keywords"];

                    TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;

                    field.SspId = termSet.TermStore.Id;
                    field.TermSetId = termSet.Id;
                    field.AnchorId = Guid.Empty;
                    field.AllowMultipleValues = true;
                    field.TextField = fieldId;
                    field.TextField = new Guid("{574C5BCE-74E8-40C8-BE90-C9338135D491}");
                    field.Update();
                    Log.Logger.LogEvent("ContentType Activation", "Updated keywords field with MMS details");
                }
            }
        }
        catch (Exception ex)
        {
            Log.Logger.LogException(ex, "Content Type Activation", ex.Message);
        }

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

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

发布评论

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

评论(1

琴流音 2024-10-24 02:39:56

为此,您应该使用 TaxonomyFieldControl:

<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken =71e9bce111e9429c" %>

You should use the TaxonomyFieldControl for this:

<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<Taxonomy:TaxonomyFieldControl FieldName="My Field Name" runat="server" id="myField"/>

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