Sharepoint学习笔记—习题系列--70-573习题解析 -(Q22-Q24)

Question22
You create a Feature.
You need to remove the link to the Site Content Type page from the Site Settings page by using the Feature.
Which element should you use in the Feature?
A. ContentType
B. ContentTypeBinding
C. HideCustomAction
D. Module

解析:
 本题就是要移除Site Setting页面中的Galleries栏下的Site Content types设置链接。如下图:

 
 实现手段是通过Feature来达到此效果。所以实际要考的是Feature的内容。
所以让我们快速的了解一下关于Feature的概念与特性。
所谓Feature就是我们所说的”功能”,你可以把想要实现的任何效果,操作,资源以及设置等等包装成一个个的”功能”,再部署到Sharepoint网站上,
功能降低了对网站进行简单自定义的复杂性,同时在将升级应用于部署时,功能相当可靠。借助功能,无需再复制大量代码即可更改简单功能。功能减少了前端 Web 服务器中可能出现的版本控制问题和不一致问题。通过功能可以更加轻松地激活或停用部署过程中所应用的功能,并且管理员仅需在用户界面上打开或关闭特定功能,即可方便地转换网站模板或定义。
功能可提供以下内容:
• 用于确定自定义代码运行位置的作用域语义
• 部署中用于安装或卸载功能的可插入行为
• 给定范围内用于激活或停用功能的可插入行为
• 用于在其作用域中存储功能所需数据的作用域属性包
• 用于分布式部署 Microsoft SharePoint Foundation 解决方案的统一框架的基础
不同的功能需要不同的文件格式,具体取决于自定义的类型。以下这是一些功能类型的文件格式:
• 内容类型绑定架构 (本题选项B就在此架构中)
• 自定义操作架构(本题所要实现的功能就在此架构中)
• 内容类型定义 (本题选项A就在此架构中)
• 委派控件
• 文档转换器
• 事件注册
• Feature.xml 文件
• 功能/网站模板关联
• 字段定义
• 列表实例
• 列表模板文件
• 模块(本题选项D就在此模式中)
• 网站定义 (Onet.xml) 文件
• 工作流定义
本题所要实现的功能就在”自定义操作定义架构”中,此架构包含如下元素
  CustomActionGroup:元素包含一组自定义操作的核心定义
  CustomAction:定义用户界面扩展,如工具栏上的按钮或网站设置页上的链接。
  HideCustomAction:元素可以隐藏默认情况下在 Microsoft SharePoint Foundation 功能的基础结构中或其他自定义操作中实现的现有操作。(这正是本题需要的知识点)
选项 A. ContentType ,属于内容类型定义架构中的元素,内容类型定义架构用于定义在功能的元素指令清单文件中创建内容类型的 XML 的结构。其内的ContentType元素用于定义单个内容类型。
B. ContentTypeBinding,属于内容类型绑定定义架构。每个指定内容类型绑定的元素指令清单文件都必须遵守内容类型绑定定义架构。其内的ContentTypeBinding元素用于指定要在 onet.xml 架构中定义的列表上设置的内容类型。

选项C. HideCustomAction就是本题的答案,针对本题的使用代码示例如下:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<HideCustomAction  
 Id="HideSiteActionFeatures"  
 HideActionId=" ManageCType "  
 GroupId="Galleries"  
 Location="Microsoft.SharePoint.SiteSettings" />
</Elements>

 

D. Module,属于模块格式。所谓模块部分就是按照类似于在 Onet.xml 文件中定义模块的方式在元素指令清单中定义模块,以便指定用于设置 SharePoint 网站的文件。可以将零个或多个 File 元素作为 Module 元素的子级。而Module元素用地指定在元素指令清单中设置 SharePoint 网站的文件。
所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/zh-cn/library/ms460318(v=office.14).aspx
http://msdn.microsoft.com/zh-cn/library/ms414790(v=office.14).aspx
http://msdn.microsoft.com/zh-cn/library/ms414322(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/bb802730.aspx

Question23
You have a SharePoint site. The current master page of the site is v4.master.
You create a custom master page named MyMasterPage.master.
You deploy the master page to /_catalogs/masterpage/.
You need to apply the custom master page to only the content pages of the site.
What should you do?
A. Rename the custom master page as v4.master and overwrite /_catalogs/masterpage/v4.master.
B. Rename the custom master page as v4.master and overwrite \14\TEMPLATE\GLOBAL\v4.master.
C. Set the MasterUrl property and CustomMasterUrl property of the site to /_catalogs/masterpage/MyMasterPage.master.
D. In the @Page directive of each page layout, set the MasterPageFile attribute to /_catalogs/masterpage/MyMasterPage.master.

解析:
 本题的意图就是把某个Site的Content Pages(内容页)的母板页设置为用户自定义的母板页。
 下面我们逐一讲解:
一、首先是了解Sharepoint的页面类型:
 Microsoft SharePoint Foundation 中主要有两种类型的页面,分别是应用程序页(Application Page) 和网站页(Site Page)。
   应用程序页(Application Page) 和网站页(Site Page)都从同一母版页继承其布局。
   应用程序页(Application Page)与传统的 Microsoft ASP.NET 3.5 网页最为相似。但是,应用程序页面并非直接派生自System.Web.UI.Page,而是派生自 LayoutsPageBase 或 UnsecuredLayoutsPageBase。
   网站页(Site Page)是由最终用户创建、编辑和自定义的页面,是可以由用户个性化定制与修改的页面。网站页是通过存储在前端 Web 服务器(Front-End Web Server)的文件系统上的模板页面设置的。在设置网站时,SharePoint Foundation 会创建指向文件系统上的页面模板实例的指针,这个指针存放在使用了此网站页的Website的Content Database中。这样,SharePoint Foundation 就可以避免重复创建每次创建网站时都要设置的页面的副本。
而本题所说的Content Pages(内容页)就是我们上面所说的Site Pages.
二、了解v4.master母板页
SharePoint2010  Foundation 使用 v4.master 作为其主要母版页。所有内容页(Content Pages)和应用程序页(Application pages)都使用 v4.master。
安装该产品后,母版页位于 %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\GLOBAL 目录中(即:本题的选项B 所示路径: \14\TEMPLATE\GLOBAL\v4.master )。
如果针对特定 SharePoint Foundation 网站编辑该母版页,则编辑后的母版页文件副本将存储在内容数据库中(即:本题的选项A:  /_catalogs/masterpage/  此路径就是一个virtual path, 存在于内容数据库[Content Database]中, 而不是存在于文件系统中。也即, 修改后的V4.master就存放在Masterpage Gallery中,你可以使用SharePoint Designer来把修改后的V4.master存放到这里。)
 所以选项A与选项B对于本题并无实质的区别,它们之间的区别就是存放位置的不同,产生的方式不同。它们的共同点就是都使用了V4.master,而按照上面的描述,V4.master是对”所有”的内容和应用程序页都适用。但本题要求的是只针对某个Site内的Content Page(内容页)。
所以使用和修改V4.master显然不符合本题的要求,因为它的影响范围不仅仅针对Content Pages还针对了Application Pages。因此,选项A. B直接可以排除掉了。
   三、内容页是如何引用母板页的
Windows SharePoint Services 提供了若干个用于引用母版页的令牌:
两个动态令牌("~masterurl/default.master" 和 "~masterurl/custom.master")
两个静态令牌("~site/default.master" 和 "~sitecollection/default.master")。

•动态令牌 "~masterurl/default.master"
此令牌使用 MasterPageFile 属性 (attribute) 和 MasterUrl 属性 (property) 的值从内容页引用母版页。例如,在页指令 <%@ Page MasterPageFile="~masterurl\default.master"%> 中,令牌 "~masterurl/default.master" 在运行时将替换为 MasterUrl 属性 (property) 中的值。此属性 (property) 包含母版页相对于服务器的完整路径(包含文件名)。
安装时,所有 SharePoint 内容页都使用此动态令牌并且 MasterUrl 属性 (property) 设置为 Windows SharePoint Services default.master;但是,您可以随时更改此值以指向不同的母版页。
重要提示: 整个字符串 "~masterurl/default.master" 均包含该令牌。

•动态令牌 "~masterurl/custom.master"
此令牌使用 MasterPageFile 属性 (attribute) 和 CustomMasterUrl 属性 (property) 的值从内容页引用母版页。令牌 "~masterurl/custom.master" 在运行时将替换为 CustomMasterUrl 属性 (property) 的值,此属性包含母版页的相对于服务器的完整路径(包含文件名)。
默认情况下,任何 SharePoint 内容页均不使用此令牌,且此令牌仅作为具有另一个共享母版页的一种方式提供。
重要提示: 整个字符串 "~masterurl/custom.master" 均包含该令牌。

•静态令牌 "~site/default.master" 和 "~sitecollection/default.master"
您可以使用这些令牌链接到相对于网站或网站集的母版页。例如,如果您的内容页位于 http://siteColl/subsite1/subsite2/default.aspx 中,并且您使用令牌 "~sitecollection/mypage.master",则内容页将使用位于 http://siteColl/mypage.master 中的母版页。如果您使用令牌 "~site/mypage.master",则内容页将使用位于 http://siteColl/subsite1/subsite2/mypage.master 中的母版页。

注意:默认情况下,MasterUrl 和 CustomMasterUrl 属性均设置为“/ _catalogs/masterpage/default.master”。如果您随后需要删除 default.master,则必须将这两个属性均设置为其他值(而不是只设置其中的一个),否则会引发一个错误,指出该 default.master 文件仍被用作该网站的母版页。(这属于选项C的知识了)

此外,您还可以通过直接更改在页指令中指定的 MasterPageFile 属性 (attribute) 的 URL,来更改内容页所使用的母版页。但与使用 MasterUrl 属性 (property) 更改母版页不同的是,它是对网页内容的更改。
有了上面的描述,我们就可以回过头来分析选项D与C了
  选项D. 即是指 Content Page中的 <% @Page MasterPageFile="/_catalogs/masterpage/MyMasterPage.master" %> 设置,很明显这种设置是不符合上面四种令牌中的任何一种使用规范的, MasterPageFile属性的设置值应该使用上述的令牌规范,例如: <% @Page MasterPageFile="~masterurl/default.master" %>  ,即一定要要内容页中使用”令牌”来引用母板页。
另外需要注意的是 在Sharepoint2010中,如果要设置应用程序页的母板页,则已经不再这样使用MasterPageFile,而是用DynamicMasterPageFile属性来代替,当然,这点对于本题是题外话。
  选项 C. 根据上面的注意点:默认情况下,MasterUrl 和 CustomMasterUrl 属性均设置为“/ _catalogs/masterpage/default.master”。如果您随后需要删除 default.master,则必须将这两个属性均设置为其他值(而不是只设置其中的一个),而且在Content Page中的 <% @Page MasterPageFile 属性的设置保持了默认的令牌,所以此修改是生效的。
   所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.masterurl.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.custommasterurl.aspx
http://msdn.microsoft.com/en-au/library/ee537576(v=office.14).aspx
http://www.cnblogs.com/sunjunlin/archive/2010/09/18/1830468.html
http://blogs.msdn.com/b/bgeoffro/archive/2009/06/22/master-pages-revisited-references-to-master-pages-in-sharepoint.aspx
http://msdn.microsoft.com/zh-cn/library/ms476046.aspx
http://msdn.microsoft.com/zh-cn/library/ee537530(v=office.14).aspx
http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-content-page-from-a-master-page-HA010167218.aspx

 

Question 24
You have a custom master page named MyApplication.master.
You need to apply MyApplication.master to only a custom application page in a SharePoint site. You must achieve the goal by using the minimum amount of effort.
What should you do?
A. Add a custom HTTP module to the Web application that modifies the master page.
B. Add a custom HTTP module to the Web application that modifies the custom application page.
C. Set the MasterPageFile attribute to ~/_layouts/MyApplication.master in the @Page directive of the custom application page.
D. Rename the custom application page as application.master and overwrite the default application.master page in the 14\TEMPLATE\LAYOUTS folder.

解析:
  本题与Question23对应,Question23是修改”内容页”的母板页,而本题则是修改”应用程序页”的母板页。而且是修改custom application page(用户自定义应用程序页)的母板页。并且:要求用最少的工作量实现目的。

  在Sharepoin中应用程序页引用母板页有3种情况:
  1. 在 Microsoft SharePoint Foundation 中,应用程序页现在可以通过 DynamicMasterPageFile 属性继承自定义的网站母版页。所谓DynamicMasterPageFile属性就是用于代替MasterPageFile属性的。
  通过使用 DynamicMasterPageFile 属性,应用程序页可引用网站母版页,而不是默认的应用程序母版页。如果需要,网站管理员可以通过管理中心或使用 SPWebApplication 对象的 MasterPageReferenceEnabled 属性,来禁止自动引用网站母版页。
  2. 针对某此需要安全保护的应用程序页, 如果这些页面在加载动态母版页时遇到问题,将改为加载 _layouts 文件夹中的安全母版页。例如:
• AccessDenied.aspx
• MngSiteAdmin.aspx
• People.aspx
• RecycleBin.aspx
• ReGhost.aspx
• ReqAcc.aspx
• Settings.aspx
• UserDisp.aspx
• ViewLsts.aspx
3. 在自定义应用程序页上使用动态母版页
如果创建自定义应用程序页,则页面必须继承自 LayoutsPageBase 基类,并且”必须”使用下面列出的动态标记之一。
动态标记:
•~masterurl/default.master – 应用程序页引用存储在 MasterUrl 属性中的母版页文件。
•~masterurl/custom.master – 应用程序页引用存储在 CustomMasterUrl 属性中的母版页文件。
  并且更为重要的是:不能在 DynamicMasterPageFile 属性中使用静态标记。
 
对于A. 通过HTTP module来修改母板页也是一种途径,实事上在普通的ASP.NET网站中,我们也可以通过此技术来实现母板页的修改,但对于Sharepoint平台而言,采用此技术则需要更多的步骤,最直接的首先要实现如何注入Preinit事件,然后还要再处理MasterPageFile属性的不同情况,以指向不同的MasterPage。但针对本题,此选项显然不能说是“最简单”的途径。
对于B. 通过HTTP module来修改应用程序页显然是怎么也达不到修改母板页的目的的。
选项D. 本选项的做法就是把应用程序页命名为母板页并覆盖原有的母板页,此方法只能用混乱来形容了。实事上,在Sharepoint2013中,借助设计管理器,您可以将 .html 文件转换为 SharePoint 2013 母版页(.master 文件)。转换后,HTML 文件和母版页相关联,因此在您编辑并保存 HTML 文件后,这些更改内容会同步到关联母版页中。但也只是针对html文件而非应用程序页(aspx页面)。

选项C. 本选项对于本题应该是“相对正确”的答案,为什么这样说呢?因为实际上此方法并不适用于Sharepoint2010,正如我们上面的知识点所述,Sharepoint2010使用了DynamicMasterPageFile属性代替MasterPageFile属性,并且当在自定义应用程序页上使用动态母版页时,不能在 DynamicMasterPageFile 属性中使用静态标记。但针对Sharepoint2007,选项C的方法又的确是生效的。

所以本题目正确选项只能是C

参考:
 http://msdn.microsoft.com/zh-cn/library/ee537530(v=office.14).aspx
http://kjellsj.blogspot.com.au/2010/07/using-page-specific-master-page-in.html
http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/369fe1ac-5611-4889-b714-5ecbe3b7e6d5
http://spdailytips.blogspot.com.au/2012/06/change-master-page-on-fly-using.html
http://www.codeproject.com/Articles/43377/SharePoint-Dynamically-Change-Master-Page

posted @ 2013-06-18 11:37  wsdj  阅读(1216)  评论(0编辑  收藏  举报