Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Graph .NET
>
Tutorial
> Create list
The following example shows you how to create a new list in a site.
C# example
using System; using System.Threading.Tasks; using Independentsoft.Graph; using Independentsoft.Graph.Sites; namespace ConsoleApp1 { class Program { static async Task Main() { try { GraphClient client = new GraphClient(); client.ClientId = "63333333-209e-454e-b7bd-55a4d201270f"; client.Tenant = "independentsoft.onmicrosoft.com"; client.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; List list = new List(); list.DisplayName = "Books"; ColumnDefinition column1 = new ColumnDefinition(); column1.Name = "Author"; column1.Column = new TextColumn(); ColumnDefinition column2 = new ColumnDefinition(); column2.Name = "PageCount"; column2.Column = new NumberColumn(); list.Columns.Add(column1); list.Columns.Add(column2); List createdList = await client.CreateList(list, "independentsoft.sharepoint.com,3333333-c666-4b40-c38"); Console.WriteLine("Id: " + createdList.Id); Console.WriteLine("CreatedTime: " + createdList.CreatedTime); if(createdList.CreatedBy != null) { if (createdList.CreatedBy.User != null) { Console.WriteLine("CreatedBy User: " + createdList.CreatedBy.User); } if (createdList.CreatedBy.Application != null) { Console.WriteLine("CreatedBy Application: " + createdList.CreatedBy.Application); } if (createdList.CreatedBy.Device != null) { Console.WriteLine("CreatedBy Device: " + createdList.CreatedBy.Device); } } Console.Read(); } catch (GraphException ex) { Console.WriteLine("Error: " + ex.Code); Console.WriteLine("Message: " + ex.Message); Console.Read(); } } } }
VB example
Imports Independentsoft.Graph Imports Independentsoft.Graph.Sites Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim task = New Task(AddressOf Run) ' Start and wait for task to end. task.Start() Console.Read() End Sub Shared Async Sub Run() Try Dim client As GraphClient = New GraphClient() client.ClientId = "63333333-209e-454e-b7bd-55a4d201270f" client.Tenant = "independentsoft.onmicrosoft.com" client.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Dim list As List = New List list.DisplayName = "Books" Dim column1 As ColumnDefinition = New ColumnDefinition column1.Name = "Author" column1.Column = New TextColumn Dim column2 As ColumnDefinition = New ColumnDefinition column2.Name = "PageCount" column2.Column = New NumberColumn list.Columns.Add(column1) list.Columns.Add(column2) Dim createdList As List = Await client.CreateList(list, "independentsoft.sharepoint.com,3333333-c666-4b40-c38") Console.WriteLine("Id: " & createdList.Id) Console.WriteLine("CreatedTime: " & createdList.CreatedTime) If createdList.CreatedBy IsNot Nothing Then If createdList.CreatedBy.User IsNot Nothing Then Console.WriteLine("CreatedBy User: " & createdList.CreatedBy.User.ToString()) End If If createdList.CreatedBy.Application IsNot Nothing Then Console.WriteLine("CreatedBy Application: " & createdList.CreatedBy.Application.ToString()) End If If createdList.CreatedBy.Device IsNot Nothing Then Console.WriteLine("CreatedBy Device: " & createdList.CreatedBy.Device.ToString()) End If End If Console.Read() Catch ex As GraphException Console.WriteLine("Error: " + ex.Code) Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*