List and content type in SharePoint

Source: Internet
Author: User

SharePoint Web Part galleries and master page galleries are implemented based on specially crafted document libraries.

 

At a lower level, WSS usesBase typesTo classify the list type. the base type of the standard list is 0, while the base type of the document library is 1. there are also less commonly used base types, such as Forum (3), voting or survey list (4), and question list (5 ). base type defines a common column set. All list types based on the same base type will automatically integrate these columns. for example, each built-in base type defines an ID field. this field allows WSS to track the items in each list by a unique integer behind the scenes and the documents in each document library. WSS also adds several columns to the base type column collection for the document library. These columns are not required for common list types.

A list instance can be created either through the WSS user interface or by a developer through the WSS object model. you can also create a list instance by adding a caml element to the feature. let's take a look at the basics of creating a list instance from the built-in list typeCodeExample.

The following example provides the code for creating a list instance. before creating a list, the code checks to ensure that a list with the same title does not exist. you will notice that the Code traverses the list of the current site, check each list, and check whether there is a matching title. if a list that matches the title does not exist, this applicationProgramThe code in will create a new instance, the type is announcements, and add a link to the quick lunch menu for easy access.

Using Microsoft. SharePoint; Class  Program { Static void Main (){ Using ( Spsite Site = New  Spsite ( "Http: // localhost" )){ Using ( Spweb Web = site. openweb ()){ String Listname ="Litware news" ; Splist List = Null ; Foreach ( Splist Currentlist In Web. Lists ){ If (Currentlist. Title. Equals (listname, stringcomparison. invariantcultureignorecase) {list = currentlist; Break ;}} If (List =Null ) {Guid listid = web. Lists. Add (listname, "List for big news items" , Splisttemplatetype . Announcements); List = web. Lists [listid]; List. onquicklaunch = True ; List. Update ();}}}}}

Note: The last part is the call to the update method on the splist. this call is required to save any changes you make to the list attributes. For example, in this example, assign true to the onquicklaunch attribute.

The list can also be accessed through the getlist method of the spweb class:

SplistAnnouncementslist = web. getlist ("/Lists/announcements");

The getlist method uses the relative site path of the List folder or the relative path of the list form as the parameter. if the list instance cannot be found, the getlist method will throw an exception of the filenotfoundexception type. the only way to check whether a list exists without throwing an exception is to traverse the list of site objects and check whether the list exists.

 

Getlist is a better way to access the list through URL. the getlistfromurl and getlistfromwebpartpageurl functions are the same as those of the getlist method, but a more general spexception exception will be thrown when a failure occurs, rather than a more descriptive filenotfoundexception exception type.

After you get a reference to a splist object, you can create a new list item by adding a splistitem object to the list's items set. splistitem is a common item type. Its fields are based on the fields of the list. you can use the following code to create and save a new list item:

SplistitemNewitem = List. Items. Add (); newitem ["Title"] ="Litware goes public! "; Newitem ["Body"] ="We all live in exciting times ."; Newitem ["Expires"] = Datetime. Now + timespan. fromdays (2); newitem. Update ();

The update method of the splistitem object will commit the modification to the list. if you do not call the update method, the data of the list items will not be saved. columns of list is specified by the display name. they can also be obtained through the column guid, or through the index of the columns set starting from 0. if a specified fields does not exist, an argumentexception exception is thrown. in some cases, you may want to traverse these fields and use the foreash statement to check whether the field actually exists.

Foreach(SpfieldFieldInList. Fields ){If(! Field. Hidden &&! Field. readonlyfield) console. writeline (field. Title );}

Traversing fields can also be useful when traversing list items. you can use the field set to access the data in the list items. to restrict the displayed field, you want to display only the fields that can be edited by the user, as shown in the following code:

 
Foreach(SplistitemItemInList. Items ){Foreach(SpfieldFieldInList. Fields ){If(! Field. Hidden &&! Field. readonlyfield) console. writeline ("{0 }= {1 }", Field. Title, item [field. ID]) ;}}

Translated from:

Chapter 6 of inside WSS 3.0

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.