Sharepoint习题——COM(Javascript)

来源:互联网 发布:微商代理授权系统源码 编辑:程序博客网 时间:2024/05/17 21:43

 

Question 10
You created a custom ASPX page that updates a list. The page is deployed to the _layouts folder.
The page contains the following code segment. (Line numbers are included for reference only.)
01 <form id="Form1" runat="Server">
02 <asp:Button id="btnUpdate" runat="server" Text="Update"></asp:Button>
03 </form>
A user attempts to update the list by using the page and receives the following error message: "The security validation for this page is invalid".
You need to prevent the error from occurring.
Which control should you include in Form1?
A. EncodedLiteral
B. FormDigest
C. InputFormCustomValidator
D. UIVersionedContent

解析:
 本题目的主要意图是实现通过一个用户自定义的ASPX页面去更新一个List的内容,重点线索是报错信息” The security validation for this page is invalid”。
 针对此错误,网上可借鉴的措施有:
 1.设置SPWeb或SPSite对象的"AllowUnsafeUpdates" 为Ture. 但有人不太推荐使用此方法,因为此方法有时候并不起作用。其原因可能是用户在一个Function中定义了SPWeb或SPSite对象,但却在另一个Function中试图操作它们.当然,具体是否如此,我没试过。
  2.还有一个方法就是使用FormDigest控件。你可以把它放置到MasterPage中,也可以放置到某个单独的页面定义中。
为什么要使用FormDigest控件呢?
出于安全考虑,默认情况下,Microsoft SharePoint Foundation 不允许从 Web 应用程序进行发布以修改数据库内容(List的内容当然是保存在内容数据库Content Database里的),除非请求页上包括安全验证。Sharepoint可以通过在请求页上添加页面指令和 FormDigest 控件来更新单个网站或网站集的数据。在 ASPX 页上插入此控件会生成安全验证或消息摘要,以帮助防止在用户因被骗而发布数据到服务器时产生的攻击。安全验证特定于用户、网站和时间段,并在可配置的时间段后过期。当用户请求页时,服务器返回插入了安全验证的页。当用户随后提交表单时,服务器会验证安全验证是否更改。
  选项A. EncodedLiteral控件主要是用于实现向ASPX页面内注入Inline Code.
例如 :
<h1>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,searchresults_pagetitle%>" EncodeMethod='HtmlEncode'/> : <% SPHttpUtility.HtmlEncode((Request.QueryString["k"].Length > 20) ? (Request.QueryString["k"].Substring(0, 20) + "...") : Request.QueryString["k"], Response.Output); %></h1>
  所以它需要实现的功能与本题目遇到的报错并没关系。

 选项 C :  InputFormCustomValidator
在 Microsoft.SharePoint.WebControls 命名空间里定义了若干验证控件用于验证用户的输入内容。这些控件如下:
• InputFormRequiredFieldValidator
• InputFormRangeValidator
• InputFormCompareValidator
• InputFormRegularExpressionValidator
• InputFormCheckBoxListValidator
• InputFormCustomValidator
InputFormCustomValidator允许用户自行定义验证的Function.

选项D. UIVersionedContent,此控件主要用于Sharepoint Fundation升级(如从Sharepoint2007升级到Sharepoint2010)后,针对不同版本的Fundation的内容呈现的。此控件也与本题的报错信息无关。
所以本题目正确选项应该是B


参考:
http://msdn.microsoft.com/zh-cn/library/ms472879.aspx

 

Question 11
You have a Web page named ShowMessage.aspx.
You create a new Web page.
You need to display the content from ShowMessage.aspx in an IFRAME on the new Web page. You must achieve this goal by using the minimum amount of effort.

What should you do?
A. Add a FormView Web Part that displays ShowMessage.aspx.
B. Use Response.Write to write text to the browser.
C. Use SP.UI.ModalDialog.showModalDialog() to display a dialog.
D. Use Response.Redirect to send users to the ShowMessage.aspx page.

解析:
 本题要求你在一个页面中用Iframe方式显示另一个页面的内容,并且要求工作量最少。
选项A. 使用FormView Web Part,因为此类Webpart主要是用于和数据库数据打交道,用于显示,更新数据库数据的,所以不适合。
选项B. Response.Write方法用于向当前的HTTP输出写入特定的字符串。如下格式:
<H3 align=center>I just want to say <% Response.Write "Hello World.</H3><BR>" %> 
Your name is: <% Response.Write Request.QueryString("name") %> <BR>
 它并不能接受另一个URL的页面地址为参数并显示那个页面,所以此选项也并不适合。
选项D. Response.Redirect,使用此方法可以显示指定的URL页面内容,示例如下:
Response.RedirectLocation = "Put The Target Page URL";
Response.StatusCode = 301;
但这种显示却并不是基于IFRAME的,因此也不适合本题。
此外,微软推荐使用的是SPUtility.Redirect 在Sharepoint中代替Response.Redirect方法。因为它提供了更多的选择参数。
选项C. SP.UI.ModalDialog.showModalDialog() 此方法会根据你提供的相关参数(包括其它页面的URL)显示一个模态窗口,如下某个示例:

复制代码
<script language="javascript" type="text/javascript">    function OpenDialogUsing_showModalDialog() {        var dialogOptions = SP.UI.$create_DialogOptions();        dialogOptions.url = '/sites/cs/md/Pages/PageinDialog.aspx';        dialogOptions.width = 650;        dialogOptions.height = 300;        SP.UI.ModalDialog.showModalDialog(dialogOptions);        return false;    }</script><a href="#" onclick="javascript:OpenDialogUsing_showModalDialog(); return false;" id="htmlAnchor">showModalDialog</a>
复制代码

 

所以,选项C是本题的答案。


参考
http://msdn.microsoft.com/zh-cn/library/ff410058(v=office.14).aspx
https://www.nothingbutsharepoint.com/sites/devwiki/SP2007Dev/Pages/How%20to%20use%20SPUtility.Redirect.aspx
http://www.chaholl.com/archive/2010/11/17/using-the-dialog-framework-in-sharepoint-2010.aspx


Question12
You create a modal dialog that displays a list of items.
You need to capture the items selected by a user.
Which code segment should you use?
A. SPItem item = SPContext.Current.Item;
B. var items = SP.ListOperation.Current.Item();
C. var items = SP.ListOperation.Selection.getSelectedItems();
D. var item = SPContext.Current.Item["Selected"];

解析:
 本题的实质就是考你在Sharepoint中如何返回List被选中的Items。
Sharepoint提供了SP.ListOperation.Selection.getSelectedItems()方法来返回List被选中的Items。此方法的返回值是一组键/值对,其中键(Key)是基于0开始计算的索引,值(Value)是一个包含两个属性的对象,两个属性就是 id和 fsObjType, 其中 id就是List Item的ID ,fsObjType 就是此Item的类型,0 = 是list item 或 document, 1= 是文件夹,所以本题目正确选项应该是C
  选项A. SPContext.Current.Item, 返回是当前List的当前Item,(要根据给定的List ID与Item ID确定),如果在上下文丢失了ID,则会出现报错,这也是为什么网上有人反应通过使用SPContext.Current.List 或 SPContext.Current.Item 找不到当前List或当前List的Item的原因,但不管怎样,它返回的都不可能返回你当前选择的若干个List Items.
  选项B. SP.ListOperation命名空间下就只有Selection类成员,找不到Current类,所以选项B是根本不存在的。
  选项D. SPContext.Current.Item["Selected"],即使能返回值,也只是返回指定List的指定Item中的某个名为”Selected”的Column的值,而并不是被选中的Item的对象集。
所以本题目正确选项应该是C

参考
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.item.aspx
http://msdn.microsoft.com/en-us/library/ff409526.aspx


Question 13
You need to add a modal dialog box to a SharePoint application.
What should you use?
A. the Core.js JavaScript
B. the Microsoft.SharePoint assembly
C. the Microsoft.SharePoint.Client assembly
D. the SP.js JavaScript

解析:
 本题考的是如何在Sharepoint中引入showModalDialog功能,ModalDialog属于Sharepoint的客户端ECMAScript对象模型,当你在Sharepoint网站的Webpart页面或者application页面(aspx page)上使用ECMAScript对象模型时,你只需要引用SP.js就可以了。
 Sharepoint提供了两个版本的Sp.js (即:Sp.js与Sp.debug.js)。它们通过Sharepoint网站的MasterPage里的scriptmanager来加载。默认情况下Scriptmanager的ScriptMode设置为auto,即自动加载Sp.js。如果你想要加载Debug版本,你需要修改web.config中的<system.web> 节下的<deployment retail="false" /> 。
  当然,当你部署到生产机时,你必须加载Sp.js而不是Sp.debug.js。
选项 A. Core.js,  Sharepoint2010的运行在很大程度上依赖于Javascript,而Core.js则包含了许多Sharepoint的运行任务,尤其是上下文菜单。如下面一些功能就是依赖于Core.js中定义的javascript功能:
 GetFirstChildElement(e)
GetLastChildElement(e)
GetCBSelectedValues(frm)
createNewDocumentWithProgID(strTemplate, strSaveLocation, strProgID, bXMLForm)
 选项B. Microsoft.SharePoint assembly 提供的是关于top-level site 和其下面的subsite或lists的相关类型与成员。是Sharepoint服务器端的最重要组件之一。没有它,Sharepoint平台就完全不能运行了。
 选项C. the Microsoft.SharePoint.Client assembly。若要使 你开发的Windows 窗体、Windows Presentation Foundation (WPF) 或其他调用 .NET 托管 SharePoint Foundation 客户端 API 的应用程序能正常工作,则客户端计算机必须已安装 (引用)上述位置的SharePoint Foundation 客户端 DLL ,你必须同时具有 Microsoft.SharePoint.Client.dll 和 Microsoft.SharePoint.Client.Runtime.dll 才能使用 .NET 托管对象模型远程开发解决方案。也就是说:若要在客户端计算机上使用包含 .NET 托管客户端 API 的 DLL,必须使用 Microsoft 的 随应用程序一起分发它们。
  显然,B与C都与模态窗口的功能无关。
所以本题目正确选项应该是D

参考
http://msdn.microsoft.com/en-us/library/ee538253.aspx
http://www.cnblogs.com/wsdj-ITtech/archive/2013/03/18/2559413.html


Question 14
You are developing an application page.
You need to create a pop-up window that uses the ECMAScript object model.
Which namespace should you use?
A. SP.UI.Menu
B. SP.UI.ModalDialog
C. SP.UI.Notify
D. SP.UI.PopoutMenu

解析:
还是关于模态窗口的题,如果看了前面的资料,几乎不用思索就选B了,因为SP.UI.ModalDialog类就是用于Sharepoint的模态窗口功能的。
  选项A. 在命名究竟SP.UI下只有如下的类:
AspMenu :   Represents an AspMenu control.
Dialog:   Represents a dialog.
DialogHostedWindow: This class and its members are reserved for internal use and are not intended to be used in your code.
ModalDialog:  Represents a modal dialog.
Notify:   Provides methods for managing notification alerts.
PopoutMenu:  Defines a pop-out menu.
Status:   Provides methods for managing status messages.
Workspace:  Represents a workspace area.
根本不存在所谓的命名空间SP.UI.Menu,所以此选项是错误的。
  选项C.D  从上面的列举可以知道SP.UI.Notify 用于显示notification alerts消息的。 SP.UI.PopoutMenu用于显示pop-out菜单,二者都和显示模态窗口无关。
所以本题目正确选项应该是B
参考:
http://msdn.microsoft.com/en-us/library/ee552096(v=office.14).aspx
http://www.a2zmenu.com/Blogs/sharepoint/SharePoint%202010%20Model%20Dialog.aspx

 

Question15

You are creating an application page that will open a dialog box.

The dialog box uses a custom master page. You write the following code segment. (Line numbers are included for reference only.)

01 <script type="text/javascript">

02   function DialogCallback(dialogResult, returnValue)

03   {

04   }

05   function OpenEditDialog(id)

06   {

07     var options = {

08              url:"http://intranet/_layouts/MsgToShow.aspx,

09              width: 300,

10              height: 300,

11              dialogReturnValueCallback: DialogCallback

12     };

13     SP.UI.ModalDialog.showModalDialog(options);

14   }

15 </script>

You need to ensure that the code opens the dialog box.

What should you do?

A. Add a script link that references SP.js.

B. Add a script link that referencesSharePoint.Dialog.js.

C. At line 13, change showModalDialog to openDialog.

D. At line 13, change showModalDialog to commonModalDialogOpen.

 

解析:

 本题在代码段没有什么错误,所以要保证能正确显示ModalDialog窗口,就只能是SP.js的引入了。参考  Question 13,所以本题没有太多讲解,正确答案应该是A

0 0
原创粉丝点击