Sharepoint学习笔记—习题系列--70-573习题解析 -(Q81-Q84)
Question 81
You need to create a Web Part that creates a copy of the out-of-the-box Contribute permission level.
Which code segment should you implement in the Web Part?
A. SPRoleDefinition myRole = new SPRoleDefinition();
myRole.Name = "Contribute";
SPContext.Current.Web.RoleDefinitions.Add(myRole);
B. SPRoleDefinition myRole = new SPRoleDefinition(SPContext.Current.Web.RoleDefinitions["Contribute"]);
myRole.Name = "MyContribute";
SPContext.Current.Web.RoleDefinitions.Add(myRole);
C. SPRoleDefinition myRole = new SPRoleDefinition(SPContext.Current.Web.RoleDefinitions["MyContribute"]);
myRole.Description = "Contribute";
SPContext.Current.Web.RoleDefinitions.Add(myRole);
D. SPRoleDefinition myRole = new SPRoleDefinition(SPContext.Current.Web.RoleDefinitions["MyContribute"]);
myRole.Name = "Contribute";
SPContext.Current.Web.RoleDefinitions.Add(myRole);
解析:
本题是想要实现复制OOTB的Contribute Permission Level对象。
Sharepoint权限系统采用 权限——角色 ——对象——关联 的概念,即:对于一个对象(如:SPWeb,SPList,SPListItem),可以通过添加某个已经包含了角色(SPRoleDefinition)的关联(SPRoleAssignment)而更改该对象的权限,而角色(SPRoleDefinition)则是提前通过SPWeb.RoleDefinitions添加到网站内的,注意:只有SPWeb有此属性可以添加角色定义,其他对象如SPSite,SPList,SPListItem均不能添加角色定义,当然他们也不需要。
相关类:
用户或用户组:SPPrincipal 扩展了两个子类:SPUser和SPGroup
权限基类:SPBasePermissions,通过或计算合成一个自定义的权限,注意:需要编辑权限的前提是有查看权限;
角色类:SPRoleDefinition,采用web.RoleDefinitions.Add(definition)的方式添加角色;
关联类:对于某个SPPrincipal添加一个SPRoleDefinition的角色,然后再将该关联添加到对象上去,注意:在未将该关联添加到对象上时,该关联都无效。
本题的四个选项都在开始创建了一个SPRoleDefinition对象,但它们采用了不同的构造参数,如下:
SPRoleDefinition():初始化一个新的不含任何Permission的SPRoleDefinition对象实例。
SPRoleDefinition(SPRoleDefinition):初始化一个新的SPRoleDefinition对象实例,此对象实例拷贝自另一个已经定义好了的SPRoleDefinition对象。
由上面的描述,我们就可以直接排除选项A了。
再来看SPContext.Current.Web.RoleDefinitions[“参数”]中的参数定义,本题要求Copy自out-of-the-box Contribute permission level,即系统默认的”Contribute”权限。只有选项B采用这个【”Contritute”】参数,而选项C.D都是Copy自用户自定义的Contribute权限。所以,只有选项B符合本题要求。
各选项的后面两句:
myRole.Name = "MyContribute";//给那个新创建的SPRoleDefinition对象命名
SPContext.Current.Web.RoleDefinitions.Add(myRole); //添加此SPRoleDefinition对象到当前Web中。
所以本题目正确选项应该是B
参考:
http://technet.microsoft.com/zh-cn/library/cc262690.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.sproledefinition.aspx
Question 82
You need to create a Web Part that verifies whether a user who accesses the Web Part page is a member of a group named Group1.
Which code condition should you use?
A. SPContext.Current.Web.Groups["Group1"].ContainsCurrentUser;
B. SPContext.Current.Web.SiteUsers[SPContext.Current.Web.CurrentUser.ID].Groups["Group1"] != null;
C. SPContext.Current.Web.SiteUsers[SPContext.Current.Web.CurrentUser.ID].Groups["Group1"] == null;
D. SPContext.Current.Web.Users["Group1"].IsDomainGroup;
解析:
本题是想验证当前用户是否属于Group1的成员。
选项B.C是想判断指定的Group对象是否为空。选项D则想判断指定的名为Group1的User是否是域内的组。只有选项A是判断Group1的成员中是否有当前User。
所以本题目正确选项应该是A
参考:
http://msdn.microsoft.com/zh-cn/library/ms479018(v=office.12).aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spgroup.containscurrentuser.aspx
Question 83
You have a SharePoint list named Assets that contains 1,000,000 items. The list contains a column named Urgent. Approximately 100 items have a value of True in their Urgent column.
You use the following line of code to retrieve the Assets list.
SPList assetsList = currentWeb.Lists["assets"];
You need to retrieve all of the items in the list that have a value of True in their Urgent column. You must retrieve the items in the minimum amount of time.
What should you do?
A. Iterate through the assetsList.Items collection.
B. Iterate through the assetsList.Fields collection.
C. Call assetsLists.GetItems and specify the SPQuery parameter.
D. Call assetsList.Items.GetDataTable() and retrieve DataRowCollection.
解析:
本题是想让你用最快的速度从一个含有大量数据的列表中检索出指定某个字段为特定值的所有Items。
我们可以采用多种办法从Sharepoint中提取数据。比如:
1.先获取SPList对象再使用For/Freach方法遍历SPListItems
2.或者也可以先创建一个CAML查询然后传递给SPQuery对象由它负责从Sharepoint中快速提取符合过滤条件的数据
3.还可以使用 LINQ to SharePoint 提供程序来进行列表的查询。
对于第1种方法,当然也是效率最差的方法,因为它要处理每一个Items,所以效率自然不高。
对于第2种方法,它要求开发人员集中分析 XML 片段,以便采用称为协作应用程序标记语言 (CAML) 的语言参数化查询,此方法效率很快,是我们通常采用的方法。
对于第3种方法, 通过使用 LINQ to SharePoint 提供程序,您可以并且仅可以查询 SharePoint Foundation 列表数据。您可使用 LINQ 语法编写查询并将结果分配到一个返回对象。第一次执行查询,将会枚举返回对象。此时,LINQ to SharePoint 提供程序会将此查询转换为一个 CAML 查询,然后像处理任何其他 CAML 查询一样处理它。
其中第2,3种有比较(CAML 对比 LINQ):
CAML 查询的主要优点是,它无需将查询从 LINQ 语法转换为 CAML 语法,因而可能会存在性能优势。
使用 LINQ 查询的主要优点包括:
可以使用集成到 C# 和 Microsoft Visual Basic 中的 LINQ 语法和 LINQ 关键字。相比之下,CAML XML 容易出错误,而且仅适用于 SharePoint Foundation。
通过使用 LINQ to SharePoint 提供程序,您使用的是强类型的列表项对象。在 SharePoint Foundation 客户端对象模型中,任意两个 SPListItem 对象都是相同的类型,即使它们表示完全不同类型的列表中的项。但是,LINQ to SharePoint 提供程序使用实体类,并且将为网站中任何列表上所使用的每个内容类型包含一个类。例如,Announcements 列表中的项是 Announcement 类型的对象,而 Tasks 列表上的项是 Task 类型的对象。
现在回到本题,分析各选项:
选项A. B.C 显然都是采用的遍历的方法 ,其中选项A是返回List的所有Items并遍历。选项B是返回List的所有Fields,并遍历。选项 D是以DataTable的方式返回所有的List Items,并遍历。
选项C.采用的是SPQuery的方法,比较高效,也是我们常用的方法。
所以本题目正确选项应该是C
参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.aspx
Question 84
You create a Web Part.
The Web Part contains a grid view named GridView1 and the following code segment. (Line numbers are included for reference only.)
01 IntranetDataContext dc = new IntranetDataContext("http://intranet");
02 MyGridView.DataSource = from announce In dc.Announcements _ ;
04 Select announce
IntranetDataContext is a LINQ context.
You need to ensure that GridView1 only displays items from Announcements that have an expiry date that is greater than or equal to the current date.
What should you do?
A. Change line 04 to the following code segment:
Select Not announce.Expires.HasValue
B. Change line 04 to the following code segment:
Select announce.Expires.Value.CompareTo(DateTime.Now) >= 0
C. Add the following line of code at line 03:
Where announce.Expires.Value.CompareTo(DateTime.Now) >= 0 _
D. Add the following line of code at line 03:
Order By announce.Expires.Value.CompareTo(DateTime.Now) >= 0 _
解析:
本题实质是考LINQ的表达语法,
LINQ 是编程语言 C# 和 Microsoft Visual Basic .NET 的一个功能。编译器是 Visual Studio 附带的。LINQ 将类似 SQL 的语法和词汇添加到每种语言,它们可用于查询数据源。但有别于其他具有不同数据源类型的语言和查询语法的是,原则上,LINQ 可用于查询任何数据源,无论它是什么。
若要能够使用 LINQ 访问数据源,需要做的就是为该数据源创建 LINQ 提供程序。
LINQ to SharePoint 提供程序是在 Microsoft.SharePoint.Linq 命名空间中定义的。它将 LINQ 查询转换为协作应用程序标记语言 (CAML) 查询。开发人员无需再了解如何编写 CAML 查询。LINQ 查询可在服务器代码中使用。
下面是一段Linq for Sharepoint的样例:
// Get DataContext from page context
DataContext data = new DataContext(SPContext.Current.Web.Url); // Get the SharePoint list
EntityList<Customer> Customers = data.GetList<Customer>("Customers"); // Query for customers from London
var londonCustomers = from customer in Customers
where customer.City == "London"
select customer; foreach (var londonCust in londonCustomers)
{
Console.Writeline("id = {0}, City = {1}",
londonCust.CustomerId,
londonCust.City);
}
参照样例可以看出,题干部分少了Where部分,即选项C部分。
你还可以参考我的与Linq For Sharepoint相关的博文:
http://www.cnblogs.com/wsdj-ITtech/archive/2011/11/03/2232530.html
http://www.cnblogs.com/wsdj-ITtech/archive/2011/11/06/2232912.html
http://www.cnblogs.com/wsdj-ITtech/archive/2011/11/08/2233008.html
所以本题目正确选项应该是C
参考:
http://msdn.microsoft.com/en-us/library/ee535491.aspx
Sharepoint学习笔记—习题系列--70-573习题解析 -(Q81-Q84)的更多相关文章
- Sharepoint学习笔记—ECM系列—文档列表的Metedata Navigation与Key Filter功能的实现
如果一个文档列表中存放了成百上千的文档,想要快速的找到你想要的还真不是件容易的事,Sharepoint提供了Metedata Navigation与Key Filter功能可以帮助我们快速的过滤和定位 ...
- Sharepoint学习笔记—ECM系列--文档集(Document Set)的实现
文档集是 SharePoint Server 2010 中的一项新功能,它使组织能够管理单个可交付文档或工作产品(可包含多个文档或文件).文档集是特殊类型的文件夹,它合并了唯一的文档集属性以及文件夹和 ...
- Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录
Sharepoint学习笔记—习题系列--70-576习题解析 为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是: 1. ...
- Sharepoint学习笔记—习题系列--70-573习题解析 --索引目录
Sharepoint学习笔记—习题系列--70-573习题解析 为便于查阅,这里整理并列出了我前面播客中的关于70-573习题解析系列的所有问题,有些内容可能会在以后更新, ...
- Deep Learning(深度学习)学习笔记整理系列之(五)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(八)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(七)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(六)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(四)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
- Deep Learning(深度学习)学习笔记整理系列之(三)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...
随机推荐
- 【原】Configuring Oracle Data Guard In Physical Standby Database
作者:david_zhang@sh [转载时请以超链接形式标明文章] http://www.cnblogs.com/david-zhang-index/p/5042640.html参照文档:https ...
- jquery select选中表单特效三级联动
好久没发帖了,今天发一个jquery select的表单三级联动,希望能对有需要的朋友有点帮助. js代码,当然还要加上jquery的包,应该都有的,这里就不发了. <script type=& ...
- storm分组模式
Shuffle grouping: Tuples被随机分配到每一个bolt’s task,以便于每一个bolt’s task获得相同数量的tuples. Fields grouping: Stream ...
- 使用uploadify上传控件无法进入后台问题分析
分别在.net mvc 和java struts2中使用到 uploadify上传 文件,遇到同样的问题,选中文件上传后,文件无法上传,打上断点后发现没有进入后台. 逐步断点发现 项目共同点是加入了 ...
- DBA需要掌握的shell知识
每个中高级DBA都需要掌握一些简单脚本的编写,这样才能从繁杂重复的基础维护工作中解脱出来,才能有时间去研究更有价值的技术.VBird在讲shell script的时候,给出了几个经典的小范例练习,对于 ...
- 网游中的网络编程3:在UDP上建立虚拟连接
目录 网游中的网络编程系列1:UDP vs. TCP 网游中的网络编程2:发送和接收数据包 网游中的网络编程3:在UDP上建立虚拟连接 TODO 二.在UDP上建立虚拟连接 介绍 UDP是无连接的,一 ...
- IOS中对象的归档
ios提供了两个类 NSKeyedArichiver NSKeyedUnarchiver对自定义对象进行归档 和解档操作 归档常见方法 - (void)encodeObject:(id)objv fo ...
- poi中getPhysicalNumberOfRows()和getLastRowNum()区别
getPhysicalNumberOfRows()获取的是物理行数,也就是不包括那些空行(隔行)的情况. getLastRowNum()获取的是最后一行的编号(编号从0开始). 通过getPhysic ...
- ADO.NET 连接方式和非链接方式访问数据库
一.//连接方式访问数据库的主要步骤(利用DataReader对象实现数据库连接模式) 1.创建连接对象(连接字符串) SqlConnection con = new SqlConnection(Co ...
- Ext.NET 4.1 最新版本破解
Ext.NET 4.1 最新版本破解 今天在将Ext.NET 4.1版本的程序发布到公网时居然要license(localhost和127.0.0.1不收费),而且一年$4999,突然间觉得这是什么鬼 ...