SharePoint Study Notes-exercise series-70-573 exercise analysis-(Q1-Q3)

Source: Internet
Author: User

Here, I will systematically analyze the practices collected from the Internet for Sharepoint 70-, and organize them into a series, which will be shared in stages and in batches for your research.

The 70-exam focuses on "know" related knowledge points, while the 70-exam focuses on "application" related knowledge points.

What needs to be stated here is: 1. do not regard this series as a question library for Sharepoint 70.

2. SharePoint learning is not for the purpose of research, but must be achieved through a large number of engineering practices.

3. However, by doing exercises, we can deepen our understanding and understanding of SharePoint-related knowledge points, which is a good way to review and organize SharePoint knowledge.

4. All questions are in English, but they do not affect your understanding of the question.

5. Due to resolution space restrictions, each articleArticleThere won't be too many questions involved, and the number of questions won't be consistent.

6. All questions are organized by question, resolution, and answer. Refer to the four sections.

7. This series is collected, organized, parsed, published, and updated. It takes some time to complete.

8. When this series has accumulated a certain amount, I will provide the List Directory, but if you are interested in it, you can sort it out by yourself.

Start our process below:

========================================================== ========================================================== ==================================

Question 1

You have a helper method named createsitecolumn that contains the following code segment.
Private Static void createsitecolumn (spweb, string columnname)
{
}
You need to add a new site column of type choice to a Sharepoint site by using the Helper method.
Which code segment shocould you include in the Helper method?


A. spfield field = new spfieldchoice (system. Web. Lists [0]. Fields, columnname );
B. Web. Fields. Add (columnname, spfieldtype. Choice, true );
C. Web. Lists [0]. Fields. Add (columnname, spfieldtype. Choice, true );
D. Web. Lists [0]. views [0]. viewfields. Add (columnname );

Resolution:

The intention of this question is to add a new site column to the SharePoint site.

Site columns is an important underlying structure of a Sharepoint website. It is a reusable column definition or template, you can allocate one or more lists to one or more SharePoint websites ). A site column is defined by several attributes, including names and field types. For example, the name of the column "title" is "title" and the field type is "text.

You can add a new site column on the SharePoint management interface, add a new site column through SharePoint designer, orCodeAdd, for example, use the following code

Http://msdn.microsoft.com/zh-cn/library/ms472869.aspx)

Using (spweb owebsite = spcontext. current. site. allwebs ["mysite"]) {spfieldcollection collfields = owebsite. lists ["mylist"]. fields; collfields. add ("myfield", Microsoft. sharepoint. spfieldtype. text, true );}

 

SpecifySharePoint siteA column(List), UseListOfFiledsAttributeAddAdd MethodSite Column, You can specify a newSitecolumnThe name, type, and whether the value must be included. Therefore, in the alternative answers provided, BIs the correct answer.

Option A: The usage method is incorrect. The use of the spfieldchoice constructor is defined as follows:

Spfieldchoice (spfieldcollection, string) initializes a new instance of the spfieldchoice Class Based on the specified field collection and field name. spfieldchoice (spfieldcollection, String, string) initializes a new instance of the spfieldchoice Class Based on the specified field collection, type name, and display name.

Obviously, the use method and parameters of option A are incorrect. In particular, the second parameter should be fieldname rather than columnname.
If you want to add a choice-type column to a list, you can use the following code: (the idea is to add a choice-type sitecolumn to the specified list first, set the backup option for this sitecolumn)

Lstcustomlist. fields. add ("ABC", spfieldtype. choice, false); // Add a new fieldlstcustomlist. update (); spfieldchoice objchoicecol = (spfieldchoice) lstcustomlist. fields ["ABC"]; // set the attribute string [] strdata = new string [2] for the newly added field; strdata [0] = "open "; strdata [1] = "close"; objchoicecol. choices. add (strdata [0]); objchoicecol. choices. add (strdata [1]); objchoicecol. update (); lstcustomlist. update ();

Option C. This is not used. Lists [] should be the listname or GUID, rather than the so-called index value. For similar usage, see the following code:

Private Static void createlist (string listname) {using (VAR site = new spsite (siteurl) {var web = site. rootweb; var listid = web. lists. add (listname, String. empty, splisttemplatetype. genericlist); var list = web. lists [listid]; List. onquicklaunch = true; List. update (); var Title = List. fields ["title"]; title. title = "name"; title. update (); var empfieldname = List. fields. add ("employee", spfieldtype. boolean, false); var ratefieldname = List. fields. add ("salary/rate", spfieldtype. currency, true); var biofieldname = List. fields. add ("Bio", spfieldtype. note, false); var view = List. defaultview; view. viewfields. add (empfieldname); view. viewfields. add (ratefieldname); view. viewfields. add (biofieldname); view. update ();}

Option D. does not use this method. If you want to add a column to a list view, you can only add existing columns to this spviewfieldcollection. Therefore, this option cannot add a new site column to the list. The code for adding a new column to the list is as follows:

 
Spsite ositecollection = spcontext. current. site; using (spweb owebsite = ositecollection. allwebs ["website_name"]) {splist olist = owebsite. lists ["list_name"]; spview oview = olist. views ["all items"]; spviewfieldcollection collviewfields = oview. viewfields; collviewfields. add ("created"); oview. update ();}

Therefore, the first item of this question should be B.

========================================================== ========================================================== ==================================

Qestion2:

You have a web application that contains the following code segment.
Private void creatingspsite ()
{
Spsite sitecollection = NULL;
Try
{
Sitecollection = new spsite ("http://contoso.com ");
}
Finally
{
}
}
You need to prevent the code segment from causing a memory leak.
Which code segment shocould you add?
A.
If (sitecollection! = NULL)
{
Sitecollection. Close ();
}
B.
If (sitecollection! = NULL)
{
Sitecollection. Dispose ();
}
C.
Sitecollection = NULL;
D.
Sitecollection. writelocked = false;

Resolution:

This is a question about SharePoint CODE memory leakage. Since Sharepoint is built on the. NET Framework, why is there Memory leakage?

This is because some Sharepoint Server objects (Services objects) such as spsite and spweb are managed objects, but to improve their running efficiency, their internal implementation code uses some unmanaged code. Therefore, you need to solve the problem of Memory leakage by yourself.

In the supply options of this question, c.d can be obviously excluded, and it should be noted that a and B.

We know that both dispose and close can be used to release the memory, but the close method can only be used when you create a spsite object and then release it. If you reference A spsite object, you cannot release it by using the close method.

Therefore, we usually recommend that you use the dispose method instead of the close method, because the close method is called in the dispose method, but it is implemented through the idisposable interface. net Framework's garbage collection mechanism will call the dispose method to release the memory related to this object. Therefore, the correct option for this question should be B.

References:

Http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spsite.close.aspx

Http://msdn.microsoft.com/zh-cn/library/aa973248 (V = office.12). aspx

========================================================== ========================================================== ==================================

Question 3

You deploy a custom web part named webpart1 to a SharePoint site.
Webpart1 contains the following code segment. (line numbers are supported ded for reference only .)
01 protected void page_load (Object sender, eventargs E)
02 {
03 spsite site = NULL;
04 try
05 {
06 spsite site = new spsite ("http://www.contoso.com/default.aspx ");
07 spweb web = site. openweb ();
08
09...
10}
11 catch
12 {
13
14}
15 finally
16 {
17
18}
19}

After you deploy webpart1, users report that the pages on the site load slowly.
You retract webpart1 from the site.
Users report that the pages on the site load without delay. You need to modify the code in webpart1 to prevent the pages from Loading slowly.

What should you do?
A.
Add the following line of code at line 08:
Site. readonly = true;
B.
Add the following line of code at line 13:
Site. Dispose ();
C.
Add the following line of code at line 17:
Site. Dispose ();
D.
Add the following line of code at line 17:
Site. readonly = true;

Resolution:

From the question analysis, page rendering is slow because a user-defined webpart is loaded. Of course, there may be many reasons for a webpart to make page presentation slow, for example: when the webpart involves data exchange with the background database, when the webpart interacts with the WebService ...... And so on.

From the Code provided in this question, only the creation of a spsite object is involved. Therefore, the question itself restricts the reason why the webpart is slowly presented to the spsite object.

For A.D, the site collection is read-only, that is, the site collection is locked and no write operations are performed. Such operations do not affect page rendering, because page rendering is a read process.

Therefore, the problem is caused by spsite Object Memory leakage. To solve this problem, use the dispose method. The problem is the time to solve the dispose method. Obviously, this method should be placed in the finally code area, this is because no matter whether your entire code is abnormal or not, the code will be executed most here. If you only put it in the catch area, when the code segment above is not abnormal, the memory leakage caused by spsite is still not solved, because the memory leakage is not in the scope of error, so it will not jump to the catch area to solve the problem.

Therefore, if this question is correct, the first item should be C.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.