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

Question 70
You plan to create one provider Web Part and two consumer Web Parts.
You need to ensure that the consumer Web Parts can receive data from the provider Web Part.
You create an interface that contains the following code segment.
public interface Interface1
{
  string Parameter1 { get; set; }
}
What should you do next?
A. Implement Interface1 in the provider Web Part.
B. Implement IWebPartField in the provider Web Part.
C. Create a set accessor for Parameter1.
D. Create a second interface and use it to communicate with the provider Web Part.

解析:
 本题其实是上题的翻版,还是考你在哪个WebPart实现题干部分定义的Interface。
选项B. IwebPartField: 属于微软针对 Web 部件基础结构提供的一组标准连接接口中的一种(还有: IWebPartRow ,IWebPartTable等 ),此类标准连接接口,主要是为了使可连接WebPart的开发更具工业化特色(如同制定了汽车轮胎的标准接口,那么不管哪家工厂生产的轮胎,只要符合此标准,就可以通用到符合此标准的汽车上),因此可连接的 Web 部件可以完全可以由不同的开发人员或公司进行开发以便彼此进行通信。所以,选项B的IwebPartField接口就是用来实现WebPart连接的,而且的确也应该是在Provider Web Part中实现的。但对本题为什么是错的呢?因为本题已经在题干部分”个性化”定制了一个接口Interface1,而并没有采用“标准化接口”方案,所以在Provider端实现的就应该是个性化定制的接口Interface1。
  选项C说的是给Parameter1创建一个设置手段,
eg:
public System.String Parameter1
{
  get { return _ PARAMETER1; }
  set { _ PARAMETER1= value; }  //创建一个Set Accessor
}
 说的是参数属性的创建,显然与本题的WebPart部件连接无关。
选项D是建议你另创建一个Interface,有点多此一举的做法。
所以本题目正确选项应该是A


参考:
http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.webparts.iwebpartfield.aspx
http://msdn.microsoft.com/en-us/library/ms469765.aspx
 


Question 71
You create a Web Part named WP1.
You need to ensure that the name of the Web Part displays as Corporate in SharePoint.
What should you do?
A. Rename WP1.webpart as Corporate.webpart.
B. In WP1.webpart, change the Title property to Corporate.
C. In the constructor of WP1.cs, add the following line of code:
Page.Title="Corporate";
D. In the Elements.xml file, change the Name property of the <File> element to Corporate.

解析:
 本题意图通过代码设置Webpart的Title属性。此属性的设置值将会显示在Webpart的Title Bar位置。
选项A. Rename WP1.webpart as Corporate.webpart. 只是修改了Wepart文件的文件名。我们知道我们可以通过建立VS2010的Web 部件项目来创建 SharePoint 网站的 web 部件。 当您创建一个 Web 部件 项目时,Visual Studio 在项目中创建一个文件夹中并将添加几个文件到文件夹。 下面就是这几个文件:
  1. Elements.xml:包含在项目中的功能定义文件使用部署 web 部件的信息。
  2. .webpart 文件:提供 SharePoint 需要显示了您在 web 部件库中的 web 部件的信息。
  3. 代码文件:包含将控件添加到 web 部件,并生成在 web 部件中的自定义内容的方法。
 本选项就是设置的.webpart文件的文件名,它并不能影响Webpart在显示界面上的Title值。
选项B. 是本题的答案,通过设置Webpart控件的Title属性当然就是修改了Webpart的Title显示值。
选项C. In the constructor of WP1.cs, add the following line of code:
Page.Title="Corporate"; 本选项的操作修改的是Webpart所在页面的Title属性,而不是Webpart控件的Title属性。
选项D. In the Elements.xml file, change the Name property of the <File> element to Corporate. 参考选项A,Elements.xml文件是用于定义文件使用部署 web 部件的信息,也即它主要是控制WebPart的部署。而且关于Element.xml文件中的<File>元素,我还没有看到修改它的所谓Name属性的情形,通常都是修改它的Path,Url与Type属性,如果查看资料,你会发现,在此处它是没有什么Name属性的。

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="WP_Resources" Path="WP_Resources">
        <File Path="links.xml" Url="links.xml" Type="GhostableInLibrary" />
    </Module>
</Elements>
所以本题目正确选项应该是B


参考:
http://msdn.microsoft.com/en-us/library/ms227561.aspx
http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.webpartpages.webpart.title(v=office.12).aspx
http://msdn.microsoft.com/en-us/library/ee231567.aspx


Question 72
You create a Web Part that contains the following logging code. (Line numbers are included for reference only.)
01 SPWeb web = SPContext.Current.Web;
02 try
03 {
04  
05 }
06 catch (Exception ex)
07 {
08  
09   System.Diagnostics.EventLog.WriteEntry("WebPart Name", ("Exception Information: " + ex.Message), EventLogEntryType.Error);
10 }
You discover that line 09 causes an error.  You need to resolve the error.
What should you do?
A. Run the code segment at line 09 inside a RunWithElevatedPrivileges delegate.
B. Add the following code at line 08:
if (web.CurrentUser.IsSiteAuditor == false)
C. Add the following code at line 08:
if (web.CurrentUser.IsSiteAdmin == false)
D. Change line 09 to the following code segment:
System.Diagnostics.EventLog.WriteEntry("WebPart Name", "Exception Information", EventLogEntryType.Error);

解析:
 本题的情景就是在你的代码中捕捉到异常,然后想把异常信息写入到EventLog中,结果出错。所以很明显,这是关于写入操作的权限问题,如果做了前面的Question59,你就能很快地确定选项A为本题的答案,即:通过RunWithElevatedPrivileges以”管理员账户身份”来完成写入操作。
 选项B. 是用来判断当前登录的用户是否是当前Site Collection的 auditor(审计者)。
选项C. 是用来判断当前登录的用户是否是当前Site Collection的 administrator(管理员)。这也解决不了问题,因为EventLog并不是归属于哪个Site Collection的,它必须要更高层次的管理员帐户才能有权写入操作。
选项D. 只是改变了写入内容,而并没提升写入的权限。
所以本题目正确选项应该是A


参考:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.issiteauditor.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.issiteadmin.aspx


 

posted @ 2013-07-26 21:10  wsdj  阅读(448)  评论(0编辑  收藏  举报