Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Graph .NET
>
Tutorial
> Create user
The following example shows you how to create an user and set user's password.
C# example
using System; using System.Threading.Tasks; using Independentsoft.Graph; using Independentsoft.Graph.Users; namespace Sample { class Program { static async Task Main(string[] args) { try { GraphClient client = new GraphClient(); client.ClientId = "67cb3333-209e-454e-b7bd-55a4d201270f"; client.Tenant = "independentsoft.onmicrosoft.com"; client.Username = "info@independentsoft.onmicrosoft.com"; client.Password = "password"; PasswordProfile passwordProfile = new PasswordProfile(); passwordProfile.Password = "QWERTY$%^123456"; User user1 = new User(); user1.AccountEnabled = true; user1.MailNickname = "alice"; user1.DisplayName = "Alice"; user1.PrincipalName = "alice@independentsoft.onmicrosoft.com"; user1.JobTitle = "Sales manager"; user1.Department = "Sales"; user1.OfficeLocation = "LA"; user1.PasswordProfile = passwordProfile; User createdUser = await client.CreateUser(user1); 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.Users 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 = "67cb3333-209e-454e-b7bd-55a4d201270f" client.Tenant = "independentsoft.onmicrosoft.com" client.Username = "info@independentsoft.onmicrosoft.com" client.Password = "password" Dim passwordProfile As PasswordProfile = New PasswordProfile() passwordProfile.Password = "QWERTY$%^123456" Dim user1 As User = New User() user1.AccountEnabled = True user1.MailNickname = "alice" user1.DisplayName = "Alice" user1.PrincipalName = "alice@independentsoft.onmicrosoft.com" user1.JobTitle = "Sales manager" user1.Department = "Sales" user1.OfficeLocation = "LA" user1.PasswordProfile = passwordProfile Dim createdUser As User = Await client.CreateUser(user1) 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*