Introduction to object models in SharePoint
The hierarchical structure of objects in Sharepoint is
Webapplication-> spsite-> spweb-> splist-> spitem. That is to say, the webapp has the largest application, including the website set spsite, the website set includes the website Web, and the list splist is down, and the list items include spitem.
Some operations on a Sharepoint object.
1. website set
Server code:
All website sets under the Application
Foreach (spsite inspcontext. Current. Site. webapplication. Sites) {// All website sets under the application program}
Website set under the current site
<span style="font-size:18px;">SPSite spSite = SPContext.Current.Site;</span>
2 websites
Root website under the website set
<span style="font-size:18px;">SPWeb spWeb =spSite.RootWeb;</span>
Websites used in the website set
<Span style = "font-size: 18px;"> foreach (spweb spsite in spsite) {// All website sets under the application program} </span>3. List
List object (a list of variable types is required many times). The document library type is 101.
<Span style = "font-size: 18px;"> foreach (splist in spweb. lists) {If (INT) splist. basetemplate = 101) {// traverse the list of all document library classes }}</span>4. Fields
Read the information of fields in each row.
Here is an example: who created this field by creating a new ribbon and using Js in it.
<span style="font-size:18px;"> var userAdress; var userName; var id = GetItemID(); function GetItemID() { var selectedItems =SP.ListOperation.Selection.getSelectedItems(); var count =CountDictionary(selectedItems); if (count > 0) { returnselectedItems[0].id; } else { return null; } } functionOnQuerySucceeded(sender, args) { this.userAdress=listItem.get_item('Created_x0020_By'); this.userName=listItem.get_item('Author').$2e_1; alert(this.userAdress+' '+this.userName) } function OnQueryFailed() { } if (id != null) { context =SP.ClientContext.get_current(); var listId =SP.ListOperation.Selection.getSelectedList(); var corporateCatalog =context.get_web().get_lists().getById(listId); listItem =corporateCatalog.getItemById(id); context.load(listItem); context.executeQueryAsync(OnQuerySucceeded, OnQueryFailed); }</span>
Summary:
These applications are examples of practical applications developed by the author, hoping to help you. I hope to realize my technical confidant. I am a self-scholar who loves computer programming.
Sharepoint2013 Object Model