public static void CreateListUnderSite(string token, string hostname, Guid siteCollectionId, Guid siteId) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/lists", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostname, siteCollectionId, siteId); var requestBody = JsonConvert.SerializeObject(new { displayName = "CreateListTest", columns = new object[] { new { name = "test1", text = new { } }, new { name = "PageCount", number = new { } } }, list = new { template = "genericList" } }); var sitesInfo = GraphApiCallHelper.PostApiJObject(token, webApiUrl, requestBody); }
/// <summary> /// the maximum bytes in any given request is less than 60 MiB. /// </summary> /// <param name="token"></param> /// <param name="hostName"></param> /// <param name="siteCollectionId"></param> /// <param name="siteId"></param> /// <param name="driveId"></param> /// <param name="fileName"></param> public static void UploadNewLargeFile(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string fileName, string filePath) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/root:/{5}:/createUploadSession", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, fileName); dynamic result = GraphApiCallHelper.PostApiJObject(token, webApiUrl, ""); var uploadUrl = result.uploadUrl.ToString(); using (var stream = new FileStream(filePath, FileMode.Open)) using (BinaryReader br = new BinaryReader(stream)) { var length = stream.Length; byte[] buffer = new byte[1024]; //byte[] buffer = new byte[2 * 1024 * 1024]; int bytesRead = 0; long totalBytesRead = 0; while ((bytesRead = br.Read(buffer, 0, buffer.Length)) > 0) { dynamic uploadResult = null; totalBytesRead = totalBytesRead + bytesRead; if (totalBytesRead == length) { // Copy to a new buffer that has the correct size var lastBuffer = new byte[bytesRead]; Array.Copy(buffer, 0, lastBuffer, 0, bytesRead); buffer = lastBuffer; } uploadResult = GraphApiCallHelper.PutApiUploadLargeFileJObject(token, uploadUrl, buffer, string.Format("bytes {0}-{1}/{2}", totalBytesRead - bytesRead, totalBytesRead - 1, length)); } } }
public static void InviteUserToFile(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId, string userEmail) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/invite", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId); var requestBody = JsonConvert.SerializeObject(new { recipients = new object[] { new { email = userEmail } }, message = "graph test", requireSignIn = true, sendInvitation = true, roles = new string[] { "write" } }); var result = GraphApiCallHelper.PostApiJObject(token, webApiUrl, requestBody); }
public static void CreateListItem(string token, string hostName, Guid siteCollectionId, Guid siteId, Guid listId) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/lists/{4}/items", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, listId); var requestBody = JsonConvert.SerializeObject(new { fields = new { Title = "CreateTest" } }); GraphApiCallHelper.PostApiJObject(token, webApiUrl, requestBody); }
public static void CreateSubFolder(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string parentDriveItemId) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/children", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, parentDriveItemId); var requestBody = JsonConvert.SerializeObject(new { name = "subfolder", folder = new { } }); var info = GraphApiCallHelper.PostApiJObject(token, webApiUrl, requestBody); }
public static void Copy(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId, string folderId) { string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/copy", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId); var requestBody = JsonConvert.SerializeObject(new { parentReference = new { driveId = driveId, id = folderId }, name = "copytest.txt" }); var info = GraphApiCallHelper.PostApiJObject(token, webApiUrl, requestBody); }