查看User Profile的名称和显示名称
在开发管理User Profile的Web Part时,需要读取和写入User Profile的属性值,但是我们往往都只知道某一属性的“显示名称”,如果要知道该属性的“名称”的话,往往还需要去管理中心点击属性的编辑按钮进去看,实在是很不方便,那么能有其他方便的方法查看到User Profile中属性的名称吗?其实只需要一段很短的代码,具体如下:
首先这段代码需要用到3个DLL,分别是Microsoft.SharePoint.dll; Microsoft.Office.Server.UserProfiles.dll; Microsoft.Office.Server.dll;然后在代码中将其引用:
1 using Microsoft.SharePoint;
2 using Microsoft.Office.Server.UserProfiles;
3 using Microsoft.Office.Server;
主要代码如下:
1 using (SPSite mySite = new SPSite("http://yourServerName/"))
2 {
3 SPServiceContext context = SPServiceContext.GetContext(mySite);
4 ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
5 ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
6 ProfileSubtypePropertyManager pspm = ps.Properties;
7 foreach (ProfileSubtypeProperty pro in pspm.PropertiesWithSection)
8 {
9 Console.WriteLine(pro.Name + "\t" + pro.DisplayName);
10 }
11 Console.ReadLine();
12 }
然后就可以看到所有的属性的名称和对应的显示名称了:

当然也可以将其写入一个文本文档,更加方便查看:
1 using (SPSite mySite = new SPSite("http://yourServerName/"))
2 {
3 SPServiceContext context = SPServiceContext.GetContext(mySite);
4 ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
5 ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
6 ProfileSubtypePropertyManager pspm = ps.Properties;
7 StreamWriter sw = File.CreateText(@"C:\userprofile.txt");
8 foreach (ProfileSubtypeProperty pro in pspm.PropertiesWithSection)
9 {
10 sw.WriteLine(pro.Name + "\t" + pro.DisplayName);
11 }
12 sw.Close();
13 }
现在我将所有的属性的名称和显示名称对应关系粘贴出来,供参考:
| 名称 | 显示名称 |
| SPS-Section-BasicInfo | 基本信息 |
| UserProfile_GUID | Id |
| SID | SID |
| ADGuid | Active Directory ID |
| AccountName | 帐户名 |
| FirstName | 名字 |
| SPS-PhoneticFirstName | 拼音名 |
| LastName | 姓氏 |
| SPS-PhoneticLastName | 拼音姓 |
| PreferredName | 名称 |
| SPS-PhoneticDisplayName | 拼音显示姓名 |
| WorkPhone | 单位电话 |
| Department | 部门 |
| Title | 职务 |
| SPS-JobTitle | 职务 |
| Manager | 经理 |
| AboutMe | 描述 |
| PersonalSpace | 个人网站 |
| PictureURL | 图片 |
| UserName | 用户名 |
| QuickLinks | 快速链接 |
| WebSite | 网站 |
| PublicSiteRedirect | 公共网站重定向 |
| SPS-DataSource | 数据源 |
| SPS-MemberOf | 隶属于 |
| SPS-Dotted-line | 非直属经理 |
| SPS-Peers | 同级 |
| SPS-Responsibility | 专业领域 |
| SPS-SipAddress | SIP 地址 |
| SPS-MySiteUpgrade | 我的网站升级 |
| SPS-DontSuggestList | “不建议”列表 |
| SPS-ProxyAddresses | 代理服务器地址 |
| SPS-HireDate | 雇用日期 |
| SPS-DisplayOrder | 显示顺序 |
| SPS-ClaimID | 声明用户标识符 |
| SPS-ClaimProviderID | 声明提供程序标识符 |
| SPS-ClaimProviderType | 声明提供程序类型 |
| SPS-LastColleagueAdded | 上一个添加的同事 |
| SPS-OWAUrl | Outlook Web Access URL |
| SPS-SavedAccountName | 保存的帐户名称 |
| SPS-SavedSID | 保存的 SID |
| SPS-ResourceSID | 资源林 SID |
| SPS-ResourceAccountName | 资源林帐户名 |
| SPS-ObjectExists | 对象已存在 |
| SPS-MasterAccountName | 主帐户名 |
| SPS-DistinguishedName | 可分辨名称 |
| SPS-SourceObjectDN | 源对象可分辨名称 |
| SPS-LastKeywordAdded | 最新添加的关键字 |
| SPS-Section-ContactInfo | 联系人信息 |
| WorkEmail | 工作电子邮件 |
| CellPhone | 移动电话 |
| Fax | 传真 |
| HomePhone | 住宅电话 |
| Office | 办公室 |
| SPS-Location | 办公地点 |
| SPS-TimeZone | 时区 |
| Assistant | 助手 |
| SPS-Section-Details | 详细信息 |
| SPS-PastProjects | 过去参与的项目 |
| SPS-Skills | 技能 |
| SPS-School | 学校 |
| SPS-Birthday | 生日 |
| SPS-StatusNotes | 状态消息 |
| SPS-Section-Delegation | 委托 |
| SPS-Section-Preferences | 新闻源设置 |
| SPS-Interests | 兴趣 |
| SPS-EmailOptin | 电子邮件通知 |
| SPS-Section-CustomProperties | 自定义属性 |
作者:Statmoon
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号