zoukankan      html  css  js  c++  java
  • Sharepoint学习笔记—习题系列--70-573习题解析 -(Q91-Q93)

    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

  • 相关阅读:
    ★一名“标题党”自我修炼的10大技巧
    字符编码笔记:ASCII,Unicode和UTF-8
    字符编码笔记:ASCII,Unicode和UTF-8
    字符编码笔记:ASCII,Unicode和UTF-8
    ★漫画:优秀的程序员具备哪些属性?
    ★漫画:优秀的程序员具备哪些属性?
    Linux 标准目录结构
    hadoop多次格式化后,导致datanode启动不了
    Linux天天见
    我的ipad应用备份
  • 原文地址:https://www.cnblogs.com/wsdj-ITtech/p/3164242.html
Copyright © 2011-2022 走看看