Independentsoft
Home
Purchase
Support
Company
Contact
Graph .NET
>
Tutorial
> Update TodoTask
The following example shows you how to update a TodoTask.
C# example
using System; using System.Collections.Generic; using System.Threading.Tasks; using Independentsoft.Graph; using Independentsoft.Graph.Todo; namespace Sample { class Program { static async Task Main(string[] args) { try { GraphClient client = new GraphClient(); client.ClientId = "63333333-209e-454e-b7bd-55a4d201270f"; client.Tenant = "independentsoft.onmicrosoft.com"; client.ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; IList<TodoTaskList> todoTaskLists = await client.GetTodoTaskLists(); for (int i = 0; i < todoTaskLists.Count; i++) { if (todoTaskLists[i].DisplayName == "Tasks") { IList<TodoTask> tasks = await client.GetTodoTasks(todoTaskLists[i].Id); for (int j = 0; j < tasks.Count; j++) { if (tasks[j].Title == "New Task") { TodoTask updateTask = new TodoTask(); updateTask.Id = tasks[j].Id; updateTask.Title = "Updated Task"; updateTask.Status = TaskStatus.Completed; await client.UpdateTodoTask(todoTaskLists[i].Id, updateTask); Console.WriteLine("Task updated."); } } } } Console.Read(); } catch (GraphException ex) { Console.WriteLine("Error: " + ex.Code); Console.WriteLine("Message: " + ex.Message); Console.Read(); } } } }
VB example
Imports System.Collections.Generic Imports Independentsoft.Graph Imports Independentsoft.Graph.Todo Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim task = New Task(AddressOf Run) 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 todoTaskLists As IList(Of TodoTaskList) = Await client.GetTodoTaskLists() For i As Integer = 0 To todoTaskLists.Count - 1 If todoTaskLists(i).DisplayName = "Tasks" Then Dim tasks As IList(Of TodoTask) = Await client.GetTodoTasks(todoTaskLists(i).Id) For j As Integer = 0 To tasks.Count - 1 If tasks(j).Title = "New Task" Then Dim updateTask As TodoTask = New TodoTask() updateTask.Id = tasks(j).Id updateTask.Title = "Updated Task" updateTask.Status = TaskStatus.Completed Await client.UpdateTodoTask(todoTaskLists(i).Id, updateTask) Console.WriteLine("Task updated.") End If Next End If Next 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*