将术语集ID映射到userprofile属性时,获取它 [英] Fetch term set id , when mapping it to userprofile property

查看:48
本文介绍了将术语集ID映射到userprofile属性时,获取它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个术语库,其中有一些术语集,例如:部门.
现在我已将该部门映射到用户个人资料属性.
我只能提取字符串(即值),但如何获取术语集的指导?

I have a termstore where i have termsets for example :Department.
Now i have mapped this department to user profile property.
I am only able to fetch string i.e value but how can i fetch the guid of term set ?

推荐答案

苛刻,

下面是供您参考的代码.在这里,我正在获取用户个人资料属性,然后找出它们是否具有与之相关联的术语集- 

Below is the code for your reference. Here I am fetching the user profile properties and then finding out whether they have a term set associated with them - 

           使用(SPSite网站=新的SPSite("http://wingtipserver/"))
            {
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
               试试
                {
                    SPServiceContext上下文=
                        SPServiceContext.GetContext(site);
                    ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                    ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));                   
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    foreach(pspm.PropertiesWithSection中的ProfileSubtypeProperty profileSubtypeProperty)
                    {
                        if(profileSubtypeProperty.CoreProperty.TermSet!= null)
                        {
                            Console.WriteLine(profileSubtypeProperty.CoreProperty.TermSet.Id);
                        }

                    }

                }

                catch(System.Exception e)
                {
                    Console.WriteLine(e.GetType().ToString()+``:" + e.Message);
                    Console.Read();
                }
            }

           using (SPSite site = new SPSite("http://wingtipserver/"))
            {
                SPServiceContext serviceContext = SPServiceContext.GetContext(site);
                try
                {
                    SPServiceContext context =
                        SPServiceContext.GetContext(site);
                    ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                    ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));                   
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    foreach (ProfileSubtypeProperty profileSubtypeProperty in pspm.PropertiesWithSection)
                    {
                        if(profileSubtypeProperty.CoreProperty.TermSet != null)
                        {
                            Console.WriteLine(profileSubtypeProperty.CoreProperty.TermSet.Id);
                        }

                    }

                }

                catch (System.Exception e)
                {
                    Console.WriteLine(e.GetType().ToString() + ": " + e.Message);
                    Console.Read();
                }
            }

如果您在获取用户个人资料并读取其属性值时需要了解Guid,则只需执行此操作- 

If you need to know the guid at the time when you are fetching a user profile and reading its property values then simply do this - 

user ["SPS部门"] .ProfileSubtypeProperty.CoreProperty.TermSet.Id

user["SPS-Department"].ProfileSubtypeProperty.CoreProperty.TermSet.Id


这篇关于将术语集ID映射到userprofile属性时,获取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆