Question 91
You have a custom user profile property named MyProperty.
You need to create a Web Part that displays the value of MyProperty for the current user.
Which code segment should you use?
A. string profile = SPContext.Current.Web.Properties("CurrentUser/MyProperty");
B. string profile = SPContext.Current.Web.Users["MyProperty"].ToString();
C. UserProfileManager profileManager = new UserProfileManager(SPServiceContext.Current);
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
string profile = userProfile["MyProperty"].ToString();
D. UserProfileManager profileManager = new UserProfileManager(SPServiceContext.Current);
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
string profile = userProfile.Properties.GetPropertyByName("MyProperty").ToString();

解析:
 本题涉及到Sharepoint的用户配置文件属性(User Profile Property)
用户配置文件属性是附加到用于描述用户个人信息的用户配置文件中的名称/值对。用户配置文件存储了用户配置文件属性信息列表。这些信息是通过导入包含用户帐户的目录中的信息或将帐户信息手动键入用户配置文件存储而获得的。默认情况下,SharePoint 可从 Active Directory 目录服务、LDAP 服务器和业务数据目录中导入信息。
 Sharepoint提供了各种情形的对象模型来操作用户配置文件属性。
 1. 服务器对象模型
管理器对象:UserProfileManager、PeopleManager
主命名空间:Microsoft.Office.Server.UserProfiles
其他关键对象:UserProfile、CorePropertyManager、ProfilePropertyManager、ProfileSubtypeManager、ProfileSubtypePropertyManager、ProfileTypePropertyManager
类库:Microsoft.Office.Server.UserProfiles.dll

2. .NET 客户端对象模型
管理器对象:PeopleManager
主命名空间:Microsoft.SharePoint.Client.UserProfiles
其他关键对象:PersonProperties、ProfileLoader、UserProfile
类库:Microsoft.SharePoint.Client.UserProfiles.dll

3. JavaScript 对象模型
管理器对象:PeopleManager
主命名空间:SP.UserProfiles
其他关键对象:PersonProperties、ProfileLoader、UserProfile
类库:SP.UserProfiles.j

4. REST 服务
管理器资源:PeopleManager
主命名空间:SP.UserProfiles
其他关键资源:PersonProperties、ProfileLoader、UserProfile
接入点:http://<siteUri>/_api/SP.UserProfiles.PeopleManager

本题属于使用服务器对象模型来操作用户配置文件属性。所以就需要用到UserProfileManager管理器对象。
下面分析各选项:
选项A. string profile = SPContext.Current.Web.Properties("CurrentUser/MyProperty"); //没用到UserProfileManager管理器对象,直接获取的是当前Web对象的Properties中名为” CurrentUser/MyProperty”的这个属性。
选项B. string profile = SPContext.Current.Web.Users["MyProperty"].ToString();//没用到UserProfileManager管理器对象,直接获取的是当前Web的所有用户中,名为MyProperty这个用户,并获取其对象名字符串。

C. UserProfileManager profileManager = new UserProfileManager(SPServiceContext.Current); //引用了UserProfileManager管理器对象
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName); //获取当前用户的UserProfile对象,此对象存储了对应用户的所有配置信息
string profile = userProfile["MyProperty"].ToString(); //UserProfile对象没有提供通过索引器来访问指定User Account的方法,所以此句表达是错误的。
D.  是本题的答案,通过UserProfile对象的GetPropertyByName 方法来获取指定的User Account的Profile对象。我们还可以通过提供SID,GUID等参数给此方法来获取相关的Profile对象。
所以本题目正确选项应该是D

参考:
http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.profilesubtypepropertymanager_members.aspx
http://pholpar.wordpress.com/2010/03/17/creating-profile-properties-and-sections-the-sharepoint-2010-way-part-2-the-code/
http://msdn.microsoft.com/en-au/library/ms543640(v=office.12).aspx
http://msdn.microsoft.com/en-us/library/ee583118.aspx

Question 92
You need to create a Web Part that adds a term set to the current SharePoint site collection's term store.
You write the following code segment. (Line numbers are included for reference only.)
01 System.Web.UI.WebControls.TextBox txtBoxTermSetToAdd = new System.Web.UI.WebControls.TextBox();
02 TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
03 TermSet addedTerm = session.TermStores[0].Groups["MyNewTermStore"].CreateTermSet(txtBoxTermSetToAdd.Text);
04
Which code segment should you add at line 04?
A. addedTerm.Export();
B. addedTerm.TermStore.CommitAll();
C. SPContext.Current.Site.WebApplication.Update();
D. SPContext.Current.Web.AllowUnsafeUpdates = true;

解析:
 本题是想要通过代码实现向Sharepoint的TermStore中添加Term Set。
 那么什么是Term Set与Term Store呢,我们先来了解如下概念:
(Term)术语 是一个可与 SharePoint Server 中的项目相关联的词或短语。
(Term Set)术语集 是一个相关术语的集合。您可以指定一栏必须包含特定术语集中的术语。
 Term Set可分为本地术语集(Local Term Set)与全局术语集(Global Term Set)
本地术语集 是在网站集上下文中创建的。例如,如果向某文档库的列表中添加一栏并创建一个将此栏绑定到的新术语集,则这个新术语集是包含此文档库的网站集的本地术语集。
全局术语集 是在网站集上下文外部创建的。例如,术语库管理员可以创建一个名为“人力资源”的术语集组,并指定一名人员来管理此术语集组。此组的管理者可以在“人力资源”术语集组中创建与人力资源(例如职务和工资等级)相关的术语集。
用户只能查看全局术语集和用户网站集本地的术语集
  术语(Term)可分为两种类型:
1.托管术语(Managed terms,):通常是预定义的,只能由具有相应权限的用户创建,且通常采用层次结构进行组织。
2.企业关键字(Enterprise keywords):只是一些已添加到 SharePoint 项目中的词或短语。所有企业关键字都属于一个名为“关键字集”的非分层术语集。
(Term Store)术语库,是一个数据库,专门用来存储托管术语和企业关键字的。
  上述的相关概念均属于Sharepoint托管元数据的范畴。托管元数据 是可定义的集中管理术语的分层集合,可将这些术语用作 Microsoft SharePoint Server 2010 中项的属性。
   Sharepoint除了提供管理工具用于元数据管理外,还提供了相应的编程模型来实现从代码级控制管理元数据。 下面就是企业元数据管理 API 中的命名空间及相应作用:
1.Microsoft.SharePoint.Taxonomy:
   包括提供由企业元数据管理提供的基本功能的类。示例包括用于管理术语、术语集、组和关键字 的类型。
2.Microsoft.SharePoint.Taxonomy.ContentTypeSync:
   包括管理网站集之间的内容类型的同步的类。
3.Microsoft.SharePoint.Taxonomy.Generic:
   包括通用元数据项目集的类。
4.Microsoft.SharePoint.Taxonomy.WebServices:
   包括用于管理富客户端应用程序和 Web 客户端应用程序中的分类的 Web 服务的类。

本题想要实现的功能就属于上述第1个命名空间(Microsoft.SharePoint.Taxonomy)。其中题干部分使用的TaxonomySession类,此类主要是用于对 SPSite 对象的所有关联的 TermStore 对象进行打包。代码如下:
  TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
  然后找到TaxonomySession类对象中的指定TermStore中的指定Group,再调用SPGroup类的CreateTermSet方法创建一个新的TermSet.代码如下:
TermSet addedTerm = session.TermStores[0].Groups["MyNewTermStore"].CreateTermSet(txtBoxTermSetToAdd.Text)
 最后一步就是向这个TermSet添加Term.
 分析各选项:
A. addedTerm.Export();看字面是想要把TermSet导出。但在类库中此方法并没有具体的实现代码。
B. addedTerm.TermStore.CommitAll();获取当前TermSet所属的TermStore,并将针对此TermStore的更新写入到数据库中保存起来。 符合本题的要求,因为我们在新添加了新的Term之后 ,就需要保存所作的更新。
C. SPContext.Current.Site.WebApplication.Update(); 保存对WebApplication的更新。
D. SPContext.Current.Web.AllowUnsafeUpdates = true; 此属性是用来标识是否允许更新数据库的。 通常而言SharePoint 2010 是要阻止开发人员对 GET 请求执行状态更改操作的。例如,在使用 GET 获取列表项或 Web 属性时,不允许 Microsoft ASP.NET 页更新列表项或 Web 属性的内容。但如果您的功能设计强制对 GET 请求执行状态更改操作,则您可通过将当前 Microsoft.SharePoint.SPWeb 类的 AllowUnsafeUpdates 属性设置为 true 以禁用此检查。请记住,在执行操作后重置该属性,并使用 try-catch-finally 块以确保异常不会将该属性保持为 true。因为此项存在安全隐患,所以,微软通常建议尽量避免使用 AllowUnsafeUpdates。就本题而言,本题不是操作TermStore更新 ,所以此属性不是
所以本题目正确选项应该是B
参考:
http://technet.microsoft.com/zh-cn/library/ee530389.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.term.aspx
http://msdn.microsoft.com/zh-cn/library/ee556337(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomysession_members.aspx

Question 93
You need to create a Web Part that displays all social tags entered by users.
Which code segment should you use?
A. TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
TermSet socialTags = session.DefaultKeywordsTermStore.SystemGroup.TermSets["Keywords"];
B. TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
TermSet socialTags = session.DefaultKeywordsTermStore.SystemGroup.TermSets["Tags"];
C. TermSet socialTags = (TermSet)SPContext.Current.Site.WebApplication.Properties["Tags"];
D. TermSet socialTags = (TermSet)SPContext.Current.Web.AllProperties["Keywords"];

解析:
 本题是想要在一个WebPart中显示所有由某用户输入的社交标签(Social tags)。
标签(Tag):是一个根据一组属性或条件来标识单条信息的单词或短语。利用标签,可以轻松查找和共享有关特定主题或任务的信息。
社会性标签(Social tags)可帮助用户通过一种有意义的方式来对信息进行分类。通过筛选特定标签,社会性标签可提高搜索结果的质量,它还可以使希望彼此共享信息的用户进行联系。
  要开始使用社交功能进行开发,您需要:SharePoint Server 2010,Visual Studio,Visual Studio 2012 Office 开发人员工具。
您还需要决定要使用的 API。一般情况下,做出此决定更取决于您创建的应用程序类型、代码的运行位置和它提供的功能。您最好使用客户端 API 进行所有 SharePoint开发。(如果您正在开发 SharePoint 相关应用程序,必须使用客户端 API。)但是,并不是 Microsoft.Office.Server.UserProfiles 程序集中所有的服务器端功能均可从客户端 API 中获取。若要查看可用的 API,请参阅 Microsoft.SharePoint.Client.Social 命名空间和 Microsoft.SharePoint.Client.UserProfiles 命名空间。也就是说,我们在Question 92提到的企业元数据管理 API 中的命名空间也同时是要用于社交功能开发的命名空间。
 下面来分析各选项:
选项A. TaxonomySession session = new TaxonomySession(SPContext.Current.Site); //获取当前Site的TaxonomySession类,此类主要是用于对 SPSite 对象的所有关联的 TermStore 对象进行打包。所以,获取了此类就获取了它所关联的TermStore对象。
TermSet socialTags = session.DefaultKeywordsTermStore.SystemGroup.TermSets["Keywords"];
//使用TaxonomySession类的DefaultKeywordsTermStore属性获取被用来存储Keywords的TermStore对象。然后再通过TermStore对象的SystemGroup属性来获取此TermStore的SystemGroup对象(它存储了Keywords 与 Orphaned Terms两个Termset),再获取Group对象中指定为”Keywords”的TermSet。

选项B. TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
TermSet socialTags = session.DefaultKeywordsTermStore.SystemGroup.TermSets["Tags"];//结构上去选项A一致,只是第二步是获取SystemGroup对象中指定为”Tags”的TermSet。问题出来了:在SystemGroup的TermSets中,只有两种Termsets,一个是”Keywords”,另一个是”Orphaned Terms”。也就是说,你是找不到”Tags”这个TermSet的。所以选项B不正确。

选项C. TermSet socialTags = (TermSet)SPContext.Current.Site.WebApplication.Properties["Tags"];//试图获取WebApplication的相关信息,与TermSet无关。
选项D. TermSet socialTags = (TermSet)SPContext.Current.Web.AllProperties["Keywords"]; //试图获取Web的相关信息,与TermSet无关。
 
所以本题目正确选项应该是A
参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.termsetcollection_members.aspx
http://msdn.microsoft.com/en-us/library/ee580616.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomysession_members.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.termstore.systemgroup.aspx

Sharepoint学习笔记—习题系列--70-573习题解析 -(Q91-Q93)的更多相关文章

  1. Sharepoint学习笔记—ECM系列—文档列表的Metedata Navigation与Key Filter功能的实现

    如果一个文档列表中存放了成百上千的文档,想要快速的找到你想要的还真不是件容易的事,Sharepoint提供了Metedata Navigation与Key Filter功能可以帮助我们快速的过滤和定位 ...

  2. Sharepoint学习笔记—ECM系列--文档集(Document Set)的实现

    文档集是 SharePoint Server 2010 中的一项新功能,它使组织能够管理单个可交付文档或工作产品(可包含多个文档或文件).文档集是特殊类型的文件夹,它合并了唯一的文档集属性以及文件夹和 ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录

        Sharepoint学习笔记—习题系列--70-576习题解析  为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是:     1. ...

  4. Sharepoint学习笔记—习题系列--70-573习题解析 --索引目录

                  Sharepoint学习笔记—习题系列--70-573习题解析 为便于查阅,这里整理并列出了我前面播客中的关于70-573习题解析系列的所有问题,有些内容可能会在以后更新, ...

  5. Deep Learning(深度学习)学习笔记整理系列之(五)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  6. Deep Learning(深度学习)学习笔记整理系列之(八)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  7. Deep Learning(深度学习)学习笔记整理系列之(七)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. Deep Learning(深度学习)学习笔记整理系列之(六)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  9. Deep Learning(深度学习)学习笔记整理系列之(四)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  10. Deep Learning(深度学习)学习笔记整理系列之(三)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

随机推荐

  1. 十六、【适合中小企业的.Net轻量级开源框架】EnterpriseFrameWork框架核心类库之单点登录SSO

    回<[开源]EnterpriseFrameWork框架系列文章索引> EFW框架源代码下载:http://pan.baidu.com/s/1qWJjo3U 单点登录(Single Sign ...

  2. nginx重定向规则入门

    nginx重定向规则的入门实例 时间:2015-12-17 15:18:03来源:网络 导读:nginx重定向规则,Nginx的重定向模块HttpRewriteModule的用法说明,nginx重定向 ...

  3. 类或方法名后加<>

    声明类型为泛型. 说明传递的参数为泛型,而不仅仅是一种类型. public void aa<T>(T a) { Console.WriteLine(a); } 调用时可写: this.aa ...

  4. CenOS6.3 ssh 公钥认证报错:Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

    转载自 http://laowafang.blog.51cto.com/251518/1364298 1.说明: ssh无密码用户远程登录,一直以来使用是debian操作系统,对用户目录权限要求没有关 ...

  5. MeshCombineUtility.cs method `GetTriangleStrip' of type `UnityEngine.Mesh' could be found

    1) Assets/Standard Assets/Scripts/MeshCombineUtility.cs(27,74): error CS1061: Type `UnityEngine.Mesh ...

  6. Nginx: could not build the server_names_hash 解决办法

    # /etc/init.d/nginx reload * Reloading nginx configuration nginx [fail] # nginx -t nginx: [emerg] co ...

  7. vim编辑器的基本使用

        VIM的操作模式     Command Mode 命令模式     Insert Mode 输入模式     Last Line Mode 底行模式       vim abc 如果文件存在 ...

  8. HTML简明教程(二)

    HTML简明教程(二) 一.HTML 图像 二.HTML 表格 三.HTML 列表 四.HTML div和 span 五.HTML 布局 六.HTML 表单和输入 七.HTML 框架 八.HTML内联 ...

  9. [Architect] ABP(现代ASP.NET样板开发框架) 翻译

    所有翻译文档,将上传word文档至GitHub 本节目录: 简介 代码示例 支持的功能 GitHub 简介 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目) ...

  10. Gradle学习系列之十——自定义Plugin(本系列完)

    在本系列的上篇文章中,我们讲到了如何自定义Task类型,在本篇文章中,我们将讲到如何自定义Plugin. 请通过以下方式下载本系列文章的Github示例代码: git clone https://gi ...