コード例 #1
0
        public async Task <List <TaskFolder> > GetAllTaskFoldersAsync(string TaskGroupId)
        {
            // Get all TaskFolder in the specified TaskGroup.
            // The property of the item to get is very limited.

            Uri    URL;
            string idAttributeName;
            string nameAttributeName;

            if (Util.UseMicrosoftGraphInMailboxViewer)
            {
                URL               = new Uri($"https://graph.microsoft.com/beta/me/outlook/taskgroups/{TaskGroupId}/taskfolders?$select=Id,Name");
                idAttributeName   = "id";
                nameAttributeName = "name";
            }
            else
            {
                URL               = new Uri($"https://outlook.office.com/api/v2.0/me/taskgroups/{TaskGroupId}/taskfolders?$select=Id,Name");
                idAttributeName   = "Id";
                nameAttributeName = "Name";
            }

            string stringResponse = "";

            try
            {
                stringResponse = await SendGetRequestAsync(URL);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Convert JSON response.

            var jsonResponse = (JObject)JsonConvert.DeserializeObject(stringResponse);
            var taskFolders  = (JArray)jsonResponse.GetValue("value");

            List <TaskFolder> result = new List <TaskFolder>();

            foreach (var folder in taskFolders)
            {
                string id   = folder.Value <string>(idAttributeName);
                string name = folder.Value <string>(nameAttributeName);

                TaskFolder newTaskFolder = TaskFolder.CreateFromId(id);
                newTaskFolder.Name = name;

                result.Add(newTaskFolder);
            }

            return(result);
        }