Question 60
You have a SharePoint site collection that contains 100 subsites.
You plan to create a Web Part. The Web Part will be deployed to each subsite.
You need to ensure that the Web Part retrieves all of the files in the root directory of the current subsite.
You write the following code segment. (Line numbers are included for reference only.)
01 SPSite site = SPContext.Current.Site;
02 SPWeb web = SPContext.Current.Web;
03
Which code segment should you add at line 03?
A. site.AllWebs[1].Files
B. Site.RootWeb.Lists[0].Items;
C. web.Files;
D. web.RootFolder.SubFolders[0].Files ;
web.Users.Add(currentUser.LoginName, currentUser.Email, currentUser.Name, "");

解析:
 本题的目的是想要部署一个Webpart在诸多Subsites上,然后各自获取各个Subsite的根目录下的所有文件。
  问题的核心是本题的哪个选项代表了各个Subsite的要目录下的所有文件。
选项A. site.AllWebs[1].Files : 如果要获取某个SPSite对象中的某个指定的Web,貌似一般不能如此用,而应该是site.AllWebs["Site_Name"]; 而且即使本选项在表达上是正确的,在实现上也只是获取某个指定的Web的Root Directory下的所有文件。
选项B. Site.RootWeb.Lists[0].Items; 此选项也不太对,一般也是使用Site.RootWeb.Lists[“List_Name”]方法来获取某个List。况且本选项也只是获取某个List下的Items,而与Web下的Files无关。
选项C. web.Files; 正是本题的答案。返回的就是当前SPWeb对象的Root Directory中的所有的文件。
选项D. web.RootFolder.SubFolders[0].Files ; //想要返回的是Web中的RootFolder,即根文件夹下的指定子文件夹下的文件。
web.Users.Add(currentUser.LoginName, currentUser.Email, currentUser.Name, "");   //想要添加一个SPUser。 很显然,本选项不符合本题的要求。
所以本题目正确选项应该是C

参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.files.aspx
http://msdn.microsoft.com/en-us/library/ee547496(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/ms412253.aspx

Question 61
You have a SharePoint site that has the URL http://contoso.com/hr.
You are creating a new Web Part.
You need to create a reference to the current subsite without having to dispose of any returned objects.
Which code segment should you use?
A. SPSite siteCollection = new SPSite("http://www.contoso.com");
SPWebCollection site = siteCollection.AllWebs;
B. SPSite siteCollection = new SPSite("http://www.contoso.com");
SPWeb site = siteCollection.RootWeb;
C. SPSite site = SPContext.Current.Site;
D. SPWeb site = SPContext.Current.Web;

解析:
  本题的意图是要在一段WebPart的后台代码中引用当前Subsite对象进行相关操作,并无须担心释放此对象的相关资源。如果你看了Question 58,相信对解决本题就不会再有困难了。
  记住如下准则:永远不要去Dispose任何使用SPContext对象获取的资源。因为SPContext对象是由Sharepoint构架管理的,此对象什么时候回收由Sharepoint自身说了算,用不着你人为的干预,而且你的强行干预反而会引起系统的崩溃。由SPContext获取的资源有SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.等等。
  因为本题是针对的Subsite,所以引用的对象应该是SPContext.Current.Web,也即选项D符合本题的要求。
  选项A.B都是人为新创建了SPSite对象,所以此类对象就需要你Dispose它们的资源。
  选项C是引用的SPSite对象而不是SPWeb对象,所以不符合本题要求。
所以本题目正确选项应该是D

Question 62
You create a Feature named Feature1. Feature1 is activated in a SharePoint site.
You create a Web Part that contains the following code.
SPSite site = new SPSite("http://intranet/site1");
SPWeb web = site.OpenWeb();
SPFeatureDefinition feature = SPFarm.Local.FeatureDefinitions["Feature1"];
You need to modify the Web Part to activate Feature1 in Site1 only.
Which code segment should you add to the Web Part?
A. site.Features.Add(feature.Id);
B. site.WebApplication.WebService.Features.Add(feature.Id);
C. web.Features.Add(feature.Id);
D. web.Site.WebApplication.WebService.Features.Add(feature.Id);

解析:
 本题想做的事情是通过一个Webpart的后台代码实现仅在Site1(这里我理解Site1就是Site Collection)中激活Feature1。
先来看题干的代码做了些什么事情:
1.SPSite site = new SPSite("http://intranet/site1");
   创建了一个SPSite对象(一个Site Collection对象),此对象代表Site1,即获取Site1这个网站集(Site Collection)对象
2.SPWeb web = site.OpenWeb();
  请注意,此句使用的OpenWeb()没有任何参数,这种用法表示返回一个SPWeb,此SPWeb对象与上面SPSite的构建函数中使用的URL(即:http://intranet/site1)相关联。在本题也就是返回Site1的Root Web对象 (我们知道Sharepoint中每一个Site Collection都有一个Top Level的Web,这个Web就是此Site Collection的Root Web)。
3.SPFeatureDefinition feature = SPFarm.Local.FeatureDefinitions["Feature1"];
  获取一个SPFeatureDefinition对象,此对象包含SPFeature对象的一系列定义(如:Feature名,Feature的标识符,Feature的作用范围和Feature的版本)。本题此处就是获取一个当前Farm中的名为Feature1的这个Feature所对应的SPFeatureDefinition对象。
 
   我们在Question 58了解了SPFeatureCollection 对象,这个对象即是功能集合对象。我们可通过使用 SPWebService、SPWebApplication、SPSite 和 SPWeb 对象的 Features 属性来访问 SPFeatureCollection。如果功能出现在集合中,则该功能已在指定的范围内激活。我们可以使用SPFeatureCollection类的Add方法添加一个新的Feature到这个功能集合对象中。所以指定的Feature被Add方法添加到对应的SPFeatureCollection功能集合对象中时,也就意味着此Feature在功能集合对象所对应的范围内被激活了。
  知道了这点,我们就知道如何去寻找答案了:即找到Site1这个Site Collection级别的SPFeatureCollection 对象,然后把我们的Feature1添加到这个功能集合对象中,如上所述,
当Feature1出现在这个功能集合中时,则表明Feature1已在指定的范围内(即本题要求的Site1这个Site Collection级别内)激活了。
   所以来看看各选项:
选项A. site.Features.Add(feature.Id); 把Feature1添加到了Site1这个对象级别的SPFeatureCollection 对象中,所以正是本题的答案。
选项B. site.WebApplication.WebService.Features.Add(feature.Id);是在SPWebService级别上的SPFeatureCollection 对象中添加Feature1,所以不符合” activate Feature1 in Site1 only”的要求。
选项C. web.Features.Add(feature.Id); 是在SPWeb级别上的SPFeatureCollection 对象中添加Feature1,所以也不符合” activate Feature1 in Site1 only”的要求。
选项D. web.Site.WebApplication.WebService.Features.Add(feature.Id); 与选项B一样,也是在是在SPWebService级别上的SPFeatureCollection 对象中添加Feature1

所以本题目正确选项应该是A
参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.openweb.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.administration.spfeaturedefinition.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spfeaturecollection.aspx

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

  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. NPM install - killed error solution

    在接手一个Node项目的时候,npm install.却出现了"killed"的错误.以为是Node版本的问题,熟练地切换了0.11与0.10版,同样无解. 由于新的npm版本吧, ...

  2. 清除WebLogic8.1缓存

    在Domain目录下面有一个以server命名的文件夹,删除整个文件夹就可以了.

  3. vs2010安装和使用

    vs2010是之前我跟老师做网站项目时安装的,这次软件工程作业我就用它了,安装过程中的截图就不存在了,我就详细说说它的使用吧. VS2010软件挺大的,下载大概要一个多小时,安装过程大概都是下一步. ...

  4. iOS-UITableView-处理cell上按钮事件(弹出警示框,页面跳转等)

    一. 目的: 实现UITableViewCell上按钮点击事件可以进行页面跳转. 二. 实现方法: 1. 用协议的方式的实现. 2. 需要自定义UITableViewCell. 三. 代码部分. ce ...

  5. 初用DataGrip,连接后看不到自己创建的数据库的问题

      1.首先,成功连接数据库服务 2.可以看到默认连接到名为"larins_qr_db"的数据库 3.这时,我想看其它的数据库怎么办? 4.OK,想要的出现了!

  6. How can I learn to program?

    黑客与画家:硅谷创业之父paul graham关于回答‘How can I learn to program’ How can I learn to program? Find a friend wh ...

  7. 50 Android Hacks阅读笔记

    Hack 1.善用weightSum和layout_weight. 问题提出:尝试做一个button的宽度是父View的一半的效果. 关键词:weightSum = 1 , layout_weight ...

  8. python之IO多路复用

    在python的网络编程里,socetserver是个重要的内置模块,其在内部其实就是利用了I/O多路复用.多线程和多进程技术,实现了并发通信.与多进程和多线程相比,I/O多路复用的系统开销小,系统不 ...

  9. Html5+css3+angularjs+jquery+webAPi 开发手机web(一)

    前言 随着浏览器的发展 HTML5+CSS3 的使用也越来越广泛,一直想学这个,想学那个折腾下来几乎没学到什么东西.工作经验告诉我,要掌握一门技术,就需要在项目中去磨练, 所以我就准备开发一个手机端的 ...

  10. 一个简单的3DTouch、Peek和Pop手势Demo,附github地址

    参考文章:http://www.jianshu.com/p/74fe6cbc542b 下载链接:https://github.com/banchichen/3DTouch-PeekAndPopGest ...