SP.ListCollection object
Represents a collection of SP.List objects.
Last modified: March 09, 2015
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
var object = new SP.ListCollection()
The ListCollection object has the following members.
Constructor
The ListCollection object has the following constructor.
|
Constructor |
Description |
|---|---|
|
Initializes a new instance of the SP.ListCollection object. |
Methods
The ListCollection object has the following methods.
|
Method |
Description |
|---|---|
|
Creates a new list or a document library. |
|
|
Gets a list that is the default asset location for images or other files, which the users upload to their wiki pages. |
|
|
Gets a list that is the default location for wiki pages. |
|
|
Returns the list with the specified list identifier. |
|
|
Returns the list with the specified title from the collection. |
|
|
Gets the list at the specified index in the collection. |
Properties
The ListCollection object has the following properties.
|
Property |
Description |
|---|---|
|
|
|
|
Gets the list at the specified index in the collection. |
The following example adds an input button on an application page that creates two new announcements lists and adds them to the list collection of the current web site.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <script type="text/ecmascript" language="ecmascript"> var listCollection; function runCode() { var clientContext = new SP.ClientContext.get_current(); if (clientContext != undefined && clientContext != null) { var web = clientContext.get_web(); this.listCollection = web.get_lists(); // Specify the title and template of the new lists. var lci1 = new SP.ListCreationInformation(); lci1.set_title('New Announcements'); lci1.set_templateType(SP.ListTemplateType.announcements); this.listCollection.add(lci1); var lci2 = new SP.ListCreationInformation(); lci2.set_title('Old Announcements'); lci2.set_templateType(SP.ListTemplateType.announcements); this.listCollection.add(lci2); clientContext.load(this.listCollection); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } } function onQuerySucceeded() { var listInfo = 'Lists on the current site:' + '\n\n'; var listEnumerator = this.listCollection.getEnumerator(); while (listEnumerator.moveNext()) { var list = listEnumerator.get_current(); listInfo += list.get_title() + '\n'; } alert(listInfo); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script> <input id="Button1" type="button" value="Run Code" onclick="runCode()" /> </asp:Content>
See ListCollection resource for more information.
Endpoint URI structure
http://<sitecollection>/<site>/_api/web/lists