// Get a sharing link. // This snippet gets a link that has `view` permissions to the file. public async Task <ResultsItem> GetSharingLink(GraphServiceClient graphClient, string id) { ResultsItem items = new ResultsItem(); // Get a sharing link for the file. Permission permission = await graphClient.Me.Drive.Items[id].CreateLink("view").Request().PostAsync(); if (permission != null) { // Get permission properties. items = new ResultsItem() { Display = permission.Link.WebUrl, Id = permission.Id }; } return(items); }
// Delete a user. Warning: This operation cannot be undone. // This snippet requires an admin work account. public async Task <List <ResultsItem> > DeleteUser(GraphServiceClient graphClient, string id) { List <ResultsItem> items = new List <ResultsItem>(); ResultsItem item = new ResultsItem(); // Make sure that the current user is not selected. User me = await graphClient.Me.Request().Select("id").GetAsync(); if (id == me.Id) { item.Properties.Add(Resource.User_ChooseAnotherUser, ""); } else { // Delete the user. await graphClient.Users[id].Request().DeleteAsync(); // This operation doesn't return anything. item.Properties.Add(Resource.No_Return_Data, ""); } items.Add(item); return(items); }
// Create a text file in the current user's root directory. public async Task <ResultsItem> CreateFile(GraphServiceClient graphClient, byte[] byteArray) { ResultsItem resultsItem = new ResultsItem(); // Create the file to upload. Read the file content string into a stream that gets passed as the file content. string guid = Guid.NewGuid().ToString(); string fileName = Resource.File + guid.Substring(0, 8) + ".jpg"; //byte[] byteArray = Encoding.ASCII.GetBytes(Resource.FileContent_New); using (MemoryStream fileContentStream = new MemoryStream(byteArray)) { // Add the file. DriveItem file = await graphClient.Me.Drive.Root.ItemWithPath(fileName).Content.Request().PutAsync <DriveItem>(fileContentStream); if (file != null) { var fileLink = await GetSharingLink(graphClient, file.Id); return(fileLink); } } return(resultsItem); }