当前用户没有足够的权限来执行此操作.在sharepoint中添加Termset

Lui*_*cia 0 c# sharepoint sharepoint-2010 sharepoint-2013

我试图将一个字段绑定到一个termset,如果termset不存在,我想通过代码创建它.但是,即使代码以提升的权限运行,我也会收到以下异常.

当前用户没有足够的权限来执行此操作.

public static void BindTaxonomyField(string taxonomyFieldId, string taxonomyNoteFieldId, string termSetName, string termGroup, SPWeb web)
        {
            try
            {
                if (web != null)
                {
                    // get the taxonomyfield from the sitecollection
                    var field = web.Fields[new Guid(taxonomyFieldId)] as TaxonomyField;
                    if (field != null)
                    {
                        // attach the note field
                        field.TextField = new Guid(taxonomyNoteFieldId);

                        // set up the field for my termstore
                        var session = new TaxonomySession(web.Site);

                        if (session.TermStores.Count > 0)
                        {
                            // get termstore values
                            TermStore ts = session.TermStores[0];
                            Group group = GetGroup(termGroup, ts);
                            if (group == null)
                            {
                                ts.CreateGroup(termGroup);
                                //throw new Exception("Group was not found in the termstore");
                            }

// ReSharper disable PossibleNullReferenceException
                            TermSet termSet = group.TermSets.Any(s => s.Name == termSetName) ? group.TermSets[termSetName] : group.CreateTermSet(termSetName);
// ReSharper restore PossibleNullReferenceException

                            //TermSet termSet = group.TermSets[termSetName];

                            // actually setup the field for using the TermStore
                            field.SspId = ts.Id;
                            field.TermSetId = termSet.Id;
                        }

                        field.Update();
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


 private void BindColumnsToTermStore(string url)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (var site = new SPSite(url))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            if (!web.AllowUnsafeUpdates)
                                web.AllowUnsafeUpdates = true;



                            BindTaxonomyField("EF810CD2-F2D2-4BD2-9ABF-C19815F13568",
                                                                           "67E6E777-0D1E-4840-B858-17400CFABD14",
                                                                           "Business Audience", "IctDocumentation",
                                                                           web);


                            web.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
Run Code Online (Sandbox Code Playgroud)

Tru*_*aya 6

如果您进入集中管理并导航到页面主容器中的术语库(这是左侧导航),则会出现一个包含少量用户名的框.您正在运行代码的帐户是否已列出?如果不把它们粘在那里.

我认为路径类似于中央管理员 - >管理服务应用程序 - >托管元数据服务 - 并且页面上的内容是调用术语商店管理员

还有一个地方你必须检查,但先检查一下,然后再次运行.

接下来要检查的是突出显示位于中央管理员 - >管理服务应用程序的管理元数据服务,并单击功能区上的权限,并确保运行代码的用户具有正确的访问权限.

我总是首先确保我知道我在运行代码是谁,然后进行检查