Access site and list data for the SharePoint server-side object Model (Part 2)

Source: Internet
Author: User

(ii) List (SPList)

Lists are the most important data container in SharePoint, and all of the data that we typically keep in SharePoint is saved in a list (a document library is also a list), so list objects are one of the most important objects in the development of SharePoint. In SharePoint, list objects use the SPList representation, and the collection of lists is represented by SPListCollection.

If it's hard to understand what the SharePoint list is all about, consider this rather inaccurate analogy, compared to the traditional data type, as follows: List (SPList) equivalent to data table (DataTable) A view (SPView) is equivalent to a Data View (DataView), a field (SPField) is equivalent to a data bar (DataColumn), and a list entry (SPListItem) is equivalent to a data row (DataRow).

Tips Tips :

After creating a list, we notice that there may be a relationship between the root and list names of the list, and the reader can try to create lists in English, Chinese, and English mixed names, and observe the rules in the list path. For all Chinese list names, the path to the list might be "Lists/list", "Lists/list1", "Lists/list2" URLs that have no practical meaning. When you create a list of Chinese names in a real-world application, you can create a list (such as "Contacts") with a meaningful English name, and then change its title to Chinese (such as "Contacts").

1, the list of access

There are several ways to get a list:

(1) Use SPWeb's Lists property to get a collection of all the lists in the site (splistcollection), and then use the indexer to get a specific list:

    • Lists[idx]:int-type indexer, based on subscript, is less commonly used;
    • Lists[id]:guid-type indexer, based on the GUID of the list;
    • The lists[title]:string type indexer, which is the most common way to get a list name.

(2) using SPWeb's GetList method, according to the list relative to the server path to obtain;

(3) Use SPWeb's getlistfromurl to get a list of relative Web sites based on the list of some view pages (you can also use the path relative to the server);

(4) Use SPWeb's Getlistsoftype method to get all the lists of a particular base type (see later).

After getting to the list collection (splistcollection), try to get the list by its Trygetlist method, based on the title of the list. This method is the newly added method in SharePoint 2010, which was most commonly used to get a list object based on the name of a list using a string indexer, but throws an exception if the list name does not exist. Using the Trygetlist method, compared to the previous fetch method, returns NULL when the list name does not exist, and is more user-friendly.

For example, the following program obtains a list of sites named "Chapters":

   1:usingnew SPSite ("Http://sp2010/book"))
   2: {
   3:   using (SPWeb Web = site.) OpenWeb ())
   4:   {
   5:     SPList chptlist = web. Lists.trygetlist ("chapters");
   6:     if null)
   7:     {
   8:       // Use the list
   9:     }
  Ten:   }
One   : }

2. Base type of list (BaseType) and list template (basetemplate)

These are two more confusing properties and concepts, but these two concepts are very important in SharePoint cross-site cross-list queries, event handlers, and Web site features (Feature), so here's a brief explanation.

The base type of the list refers to the base type of the list, and there is a large difference in the underlying structure between lists of different basic types, and SharePoint has built-in lists of 5 basic types (refer to Spbasetype enumeration types):

    • General List (GenericList ): The type of most lists, such as notifications, calendars, contacts, etc.;
    • Document library (DocumentLibrary ): A list of stored files, such as a document library, a picture library, a form library, etc.
    • Discussion board (Discussionboard ): List of discussion boards;
    • Survey (Survey ): Survey list;
    • problem Tracking (Issue ): Problem tracking list.

As can be seen from the above classification, the base type of the list defines the basic structure and the general function of the list, and the list template more specifically defines a list of specific structure, fields, views and other information, we see in the list creation page Each link, basically is a different list template, Of course, we can also save a list of well-configured fields and view information as a custom list template by saving the list as a template.

There are many types of list templates built into SharePoint, each with an integer ID, such as a notification list with a template ID of 104 and a document library template with ID 101. These built-in list templates and ID values can refer to the Splisttemplatetype enumeration types in the SDK.

3. Common properties of the list

The common properties of SPList are as follows:

Name

Type

Description

Basetemplate

Splisttemplatetype

List templates

BaseType

Spbasetype

Base type of the list

DefaultView

SPView

Default view of the list

RootFolder

SPFolder

The root folder of the list

Title

String

Title of the list

Items

SPListItemCollection

All entries in the list (non-folder entries)

Folders

SPListItemCollection

All folder entries in the list are explained in the following article

Fields

Spfieldcollection

All fields in the list

Forms

SPFormCollection

Forms in the list (such as new, edit, view, etc.)

Views

Spviewcollection

All views in the list

For example, the following program lists all the lists in the Web site and prints out the title of their list:

   1:usingnew SPSite ("Http://sp2010/book"))
   2: {
   3:   using (SPWeb Web = site.) OpenWeb ())
   4:   {
   5:     foreach  in Web. Lists)
   6:       Console.WriteLine (list. Title);
   7:   }
   8: }

Access site and list data for the SharePoint server-side object Model (Part 2)

Related Article

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.