SharePoint class library Summary

Source: Internet
Author: User
WriteProgramReasonable Use of try-catch statements is a good programming habit.
Try-catch for all statements that may cause errors as much as possible,
If necessary, capture each specific exception and provide more friendly error information, making the program more user-friendly.

System. Web. UI. webcontrols. webparts; indicates the location of the webpart class.

Controls include button, Textbox, htmltablecell, and Labe.

Its public attributes include:
Allowminimize: whether to allow minimization;
Caption: A description of the webpart, followed by the text behind the title;
Description: Introduction to webpart;
Framestate: the status of the webpart, either minimized or normal;
Frametype: specifies the type of the webpart border, which can be set as follows: default (default: set by webpartzone where the webpart is located), none, standard, titlebaronly (with a title bar without Borders)
Height/width: the length and width of the webpart;
ID: the ID of the webpart;
Partimagelarge/partimagesmall: A webpart image. By setting this image, you can easily find the webpart when managing the webpart, which is separated from other webparts;
Title: The title of a webpart;
Zoneid: ID of the webpartzone in which the webpart is located;

Webpart also has some public or protected functions,
Controls. Add ("control object") adds controls to the webpart.

Protected member:
Protected override void render (system. Web. UI. htmltextwriter writer) // by default, controls in controls are traversed and output in sequence.
Protected override void onload (eventargs e) // events processed during the first loading
Protected override void createchildcontrols () // called by the Asp.net page framework to notify the Server Control to create any child controls they contain for sending back or rendering preparation.

Microsoft. SharePoint;
// This name provides basic object models for website content in WSS, such as websites, lists, files, and users.

Spsite class
// A collection of websites

Constructor: spsite (string URL), spsite (guid X)

// GUID is the unique identifier of an object. The GUID can be used to obtain the object instance, such as spsite, spweb, splist, spview, area, and arealisting.
// Some also use integers as identifiers, such as table item splistitem, role sprole, and user spuser

Allwebs attributes
// You can obtain all the websites in the website, including one top-level website and all its subwebsites.
// You can use webs [int Index], webs [String url], and webs [guid] to obtain specific spweb objects.

Rootweb attributes
// This property is a spweb type variable. It corresponds to the top-level website in the website set and gradually obtains the hierarchical structure of the website.

Openweb Functions
// Return a spweb type variable. You can use this function to obtain a specific website in the website set.
Openweb ();
Openweb (guid );
Openweb (string URL );

Spweb
// Webpage content set

// Most WSS-related content is obtained by using some member variables of spweb. These members mainly include:

Allusers: All website members and users who browse the website through domain groups;
Files: All files under the website;
Folders: all directories under the website;
Groups: all cross-site user groups;
Lists: All lists under the website;
Listtemplates: All List Templates under the website;
Permissions: the permissions on the website;
Roles: All roles under the website;
Users: all users of the website;
Webs: All Sub-websites of the website;

// In addition, some member variables of spweb correspond to some attributes of the website, such:
Allowanonymousaccess: whether the website allows anonymous access (read-only );
Author: the creator of the website;
Created: the website creation time;
Currentuser: the current user;
ID: guid that uniquely identifies the website;
Isrootweb: whether the website is a top-level website;
Parentweb: the parent website of the website;
Site: the website set to which the website belongs;
Title: The title of the website;
URL: the absolute URL of the website;
Webtemplate: template of the website;

// Some methods provided by the spweb object
GetFile: Get the object (spfile) of a file through the URL );
Getfolder: Get the spfolder object of a directory through URL;
Getlistoftype: gets the set of lists of specific types;
Getsubwebsforcurrentuser: Obtain the subwebsite of the website (you can specify a template );
Getviewfromurl: Get a view spview of a list through the URL;
Saveastemplate: Save the website as a template;
Searchdocuments: Search for the document library of a website (full-text retrieval must be enabled );
Searchlistitems: searches for list entries;
Update: make changes to website attributes take effect;
// It takes effect only after update when modifying Object Attributes

Splist class
// List Function
// The main method to obtain the splist is to access the splistcollection type attribute spweb. Lists.
// There are three methods to obtain a specific list object from this set:
Lists [string name];
Lists [guid];
Lists [int Index];

// Call the splistcollection. Add method to add a list. After the list is created, the guid of the new list is returned.
Add (string tile, string description, splisttemplate template );
// The First Two Parameters specify the name and description of the list respectively. The first two parameters are a splisttemplate variable,
// Specify the list template object required for the list creation. This object can be obtained using the spweb. listtemplates attribute;

Add (String title, string description, splisttemplatetype type );
// The 3rd parameters are specified in the splisttemplatetype enumeration list template.
// List Templates of the basic types of websites by default. If you create a custom list, you can use splisttemplatetype. genericlist as this parameter;

Add (String title, string description, splisttemplate template, spdoctemplate doctemplate );
// This method creates a document library, 3rd template objects in the List specified by parameters, and 4th objects in the document library specified by parameters,
// This object can be obtained through the spweb. doctemplates attribute;

// Call the splistcollection. Delete method to delete the list.
Delete (guid); // you can use guid to delete a list.

// Splist has the following common attributes:
Basetemplate: list template corresponding to the list;
Basetype: basic type of the list;
Defaultview: the default view object of the list;
Enableattachments: whether to add attachments to the list;
Enablemoderation: whether the approval function is enabled for this list;
Fields: a set of list fields;
Forms: a collection of list forms, including browsing, adding, and modifying pages;
ID: indicates the unique guid of the list;
Items: a set of list entries;
Parentweb: the object of the website where the list is located;
Title: The title of the list;
Views: a set of views of the list;
// After modifying attributes, use the splist. Update method to make the modification take effect.

Spview class
// In addition to displaying diversified data, a view also plays an important role in data filtering and sorting.
// In the SharePoint environment, you can directly modify the content of the view. By using calculated fields, you can enrich the filtering and sorting functions;

// There are three methods to obtain the spview object:
Use the list. defaultview attribute to obtain the default view of the list;
Use the spweb. getviewfromurl method to obtain the view based on the URL. In actual use, you can use this method to obtain a view first and then obtain the list object of the view;
Use List. Views to get all views of the list, and then use the following three methods to get a specific view:
Views [string name];
Views [guid];
Views [int Index];

// Add a view by using the spviewcollection. Add method:
Add (string name, stringcollection fields, string query, uint rowlimit, bool paged, bool makedefault );
// The name parameter specifies the view name, and the fields parameter specifies the set of field names to be displayed,
// The query parameter specifies the data filtering conditions. The rowlimit parameter specifies the maximum number of list entries returned in the view at a time,
// The paged parameter specifies whether the view supports paging. The makedefault parameter specifies whether the view needs to be used as the default view;

Add (string name, stringcollcection fields, string query, uint rowlimit, bool paged, bool makedefault, spviewcollection. spviewtype type, bool personalview );
// The preceding parameter is the same as the preceding parameter. The type parameter specifies the basic type of the view. The personalview parameter specifies whether the view is a personal view.

// Unlike the list addition method, the spview object instead of a guid is returned when you try to add a method;
// Delete a view using the spviewcollection. Delete method and using the view guid as the parameter;
// When a view is viewed on the default page, the page flip function of the view is only "Next" but not "previous". If you need to implement the forward page flip function, you need to write a program to complete it yourself;

// Attributes commonly used in spview are as follows:
ID: The list object (splist) that identifies the view );
Parentlist: list object containing the view;
Propertiesxml: basic information of the view, including URL, name, and type;
Query: an XML string used to filter data in the view;
Schemaxml: View information, including basic information, such as filtering and grouping;
Title: The name of the view;
Viewfields: the set of fields to be displayed in the view;
URL: displays the URL corresponding to the view;
// Call spview. Update to make the modification take effect after modifying attributes

Spfield class
// Corresponds to the Field object in the list. The Sharepoint list consists of several fields. Each field can be set to a different data type or has different attribute settings, such as the default value, hidden or empty.

// The method to obtain the spfield object is to obtain all fields through the splist. Fields attribute, and then obtain specific fields through the following two methods:
Fields [String dispname];
Fields [int Index];

// You can add fields to the list using the following methods:
Add (string dispname, spfieldtype type, bool brequired );
Addlookup (string dispname, guid lookuplistid, bool brequired );
Addfieldasxml (string strxml );

// spfield has the following common attributes.
defaultformula: formula of the calculated field;
defaultvalue: Default Value of the field;
Description: Description of the field;
filterable: whether the field can be filtered;
hidden: whether the field is displayed in the list;
inernalname: Internal name of the field;
parentlist: the object in the list where the field is located;
readonlyfield: whether the field is read-only;
required: whether the field is required when entering data;
schemaxml: information set for this field;
sortable: whether the field can be sorted;
title: The field name of this field, that is, the display name;
type: the type of this field, which is an enumeration of the spfieldtype type.
// The update takes effect only after modification.;
// each field has two names: Display name and internal name. They correspond to spfield. Title and spfield. internalname in the object model.
// spfield subclasses include spfieldtext, spfieldlookup, and spfieldnumber.

Splistitem class
// In the actual operation of the list, the list item that is finally to be accessed is the list item that is part of the data content ).
// Obtain a set of list entries before accessing a specific entry in the list.
// Obtain the List entry set:
Use the splist. Items attribute to return all list entries in the list. You can use this method to obtain or traverse all list entries;
Use the splist. getitems method to obtain some list entries purposefully:
Getitems (spview view );
Getitems (spquery query); // spquery is a class for querying list entries. by defining a query, you can easily obtain the list entries you want;
// Spquery provides two constructor types: one is parameter-free, and the other can contain a spview parameter, that is, two queries are performed on the specified view.
// One of the core attributes of spquery is the query attribute, which is a string type. It adopts a specially defined XML format, namely, caml (Collaborative Application Markup Language)
// Describes a query condition. In fact, the query string is equivalent to the spview. query attribute.
Getitems (spquery query, string viewid );

// When using spquery, you must re-construct each time you use it (that is, use the new operator to regenerate a new object), and then specify the query attribute;
// Otherwise, if no re-construction is performed, even if different query attributes are specified, the query result of the first specified query condition is always obtained during each query.

// After obtaining the set, you can obtain a specific list entry using the following two methods.
Items [int Index];
Getitembyid (int id); // each list entry has a unique ID in this list

// After obtaining the List entry, you can access or modify the content of the entry. The most common method to access a field of the entry is: item [String fieldname].
// Fieldname indicates the display name of the field, or the internal name of the field.

// Splistitem attributes
Attachments: The attachment set of the List entry;
File: if the list is a document library, the object of the file is obtained;
ID: an integer that uniquely identifies a list entry;
Moderationinfomation: The approval information of the List entry;
Parentlist: the object in the list where the List entry is located;
XML: returns all data in the List entry in XML format;
// After the attribute is modified, the modification takes effect through splistitem. Update;

// Add a list entry Method
Splistitemcollection. Add ()
// This method directly returns an empty splistitem object without parameters,
// Modify the content of each field through the object, and then call update to add the entry to the list.

// Delete A List entry
Splistitemcollection. deletebyid (int id );
Splistitemcollection. Delete (INT index );

// In the splistitemcollection class, there is a very useful method: getdatatable is
Datatable getdatatable ();
// This method returns a able object composed of these list entries to bind the data to some display controls. If no entry exists, null is returned;

[This article is reprinted for your own learning and work]

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.