예제 #1
0
        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);
        }
예제 #2
0
        private static JObject GetSiteCollectionByUrl(string token, string siteUrl)
        {
            var    siteUri   = new Uri(siteUrl);
            string webApiUrl = string.Format("{0}/sites/{1}:{2}", GraphAPIVersion.V1, siteUri.Host, siteUri.AbsolutePath);

            return(GraphApiCallHelper.GetApiJObject(token, webApiUrl));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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));
                    }
                }
        }
예제 #6
0
        /// <summary>
        /// query 指定 field value
        /// </summary>
        /// <param name="token"></param>
        /// <param name="hostName"></param>
        /// <param name="siteCollectionId"></param>
        /// <param name="siteId"></param>
        /// <param name="listId"></param>
        /// <param name="itemId"></param>
        /// <param name="fields"></param>
        public static void GetListItemSpecifiedFields(string token, string hostName, Guid siteCollectionId, Guid siteId, Guid listId, int itemId, params string[] fields)
        {
            string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/lists/{4}/items/{5}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, listId, itemId);

            webApiUrl = string.Format("{0}{1}", webApiUrl, CreateQueryParamFormQueryListItemField(fields));
            var result = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
        }
예제 #7
0
 public static void GetDriveItemContentByPath(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string filePath)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/root:/{5}:/content", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, filePath);
     var    info      = GraphApiCallHelper.GetApiResponseContent(token, webApiUrl);
 }
예제 #8
0
 /// <summary>
 /// 当前该方法不可用
 /// </summary>
 /// <param name="token"></param>
 /// <param name="hostName"></param>
 /// <param name="siteCollectionId"></param>
 /// <param name="siteId"></param>
 /// <param name="driveId"></param>
 /// <param name="driveItemId"></param>
 public static void ListDriveItemChildrenByItemId(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, int driveItemId)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/children", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, driveItemId);
     var    info      = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #9
0
        public static void Delete(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId)
        {
            string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId);

            GraphApiCallHelper.DeleteApi(token, webApiUrl);
        }
예제 #10
0
 public static void Move(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}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId);
     var    requestBody = JsonConvert.SerializeObject(new { parentReference = new { id = folderId }, name = "movetest.txt" });
     var    info        = GraphApiCallHelper.PatchApiJObject(token, webApiUrl, requestBody);
 }
예제 #11
0
 public static void GetVersions(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId)
 {
     string  webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/versions", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId);
     dynamic result    = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #12
0
 private static void GetListsWithSystem(string token, string siteId)
 {
     string  webApiUrl    = string.Format("{0}/sites/{1}/lists/daf86790-5321-4e47-bcaf-5b89fc441ef8/items", GraphAPIVersion.V1, siteId);
     dynamic allListsInfo = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
     var     subSiteCount = allListsInfo.value.Count;
 }
예제 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="token"></param>
 /// <param name="hostname">longgod.sharepoint.com</param>
 /// <param name="siteCollectionId">a4e0e820-b750-4b37-beee-fccdd463a3f2</param>
 /// <param name="siteId">0a09151c-3651-40b4-9d47-dd477e4b9dae</param>
 /// <param name="listId">bb3f653d-e66f-43fb-98db-db608d47ba78</param>
 public static void GetListUnderSite(string token, string hostname, Guid siteCollectionId, Guid siteId, Guid listId)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/lists/{4}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostname, siteCollectionId, siteId, listId);
     var    sitesInfo = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #14
0
        public static void UploadNewFile(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string parentFolderId, string fileName)
        {
            string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}:/{6}:/content", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, parentFolderId, fileName);

            GraphApiCallHelper.PutApi(token, webApiUrl, System.Text.Encoding.Default.GetBytes("Test"));
        }
예제 #15
0
 public static void GetListItem(string token, string hostName, Guid siteCollectionId, Guid siteId, Guid listId, int itemId)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/lists/{4}/items/{5}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, listId, itemId);
     var    result    = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #16
0
 public static void UpdateListItemFieldValues(string token, string hostName, Guid siteCollectionId, Guid siteId, Guid listId, int itemId)
 {
     string webApiUrl   = string.Format("{0}/sites/{1},{2},{3}/lists/{4}/items/{5}/fields", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, listId, itemId);
     var    requestBody = JsonConvert.SerializeObject(new { Title = "UpdateTest" });
     var    result      = GraphApiCallHelper.PatchApiJObject(token, webApiUrl, requestBody);
 }
예제 #17
0
 /// <summary>
 /// 暂时还不清楚search query对应的是什么属性
 /// </summary>
 /// <param name="token"></param>
 /// <param name="searchQuery">"jqzhao1"</param>
 public static void SearchSiteCollection(string token, string searchQuery)
 {
     string apiUrl   = string.Format("{0}/sites/?$search={1}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, searchQuery);
     var    siteInfo = GraphApiCallHelper.GetApiJObject(token, apiUrl);
 }
예제 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="token"></param>
 /// <param name="hostName">longgod.sharepoint.com</param>
 public static void GetTenantRootSiteCollectionInfoByHostName(string token, string hostName)
 {
     string apiUrl   = string.Format("{0}/sites/{1}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName);
     var    siteInfo = GraphApiCallHelper.GetApiJObject(token, apiUrl);
 }
예제 #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="token"></param>
 /// <param name="hostName">longgod.sharepoint.com</param>
 /// <param name="siteId">dd328351-9c84-4c36-b391-6673d2ce9ace</param>
 public static void GetSiteCollectionInfoById(string token, string hostName, Guid siteId)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteId);
     var    siteInfo  = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #20
0
        public static void ReplaceExistFile(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId)
        {
            string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/content", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId);

            GraphApiCallHelper.PutApi(token, webApiUrl, System.Text.Encoding.Default.GetBytes("Test2"));
        }
예제 #21
0
 /// <summary>
 /// DriveId当前仅知道可以通过GetAllDrives方法的返回值获取
 /// </summary>
 /// <param name="token"></param>
 /// <param name="hostname"></param>
 /// <param name="siteCollectionId"></param>
 /// <param name="siteId"></param>
 /// <param name="driveId">b!IOjgpFC3N0u-7vzN1GOj8hwVCQpRNrRAnUfdR35Lna49ZT-7b-b7Q5jb22CNR7p4</param>
 public static void GetDriveByDriveId(string token, string hostname, Guid siteCollectionId, Guid siteId, string driveId)
 {
     string webApiUrl = string.Format("{0}/sites/{1},{2},{3}/Drives/{4}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostname, siteCollectionId, siteId, driveId);
     var    driveInfo = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #22
0
 public static void GetSiteInfoByUrl(string token, string siteUrl)
 {
     var    siteUri   = new Uri(siteUrl);
     string webApiUrl = string.Format("{0}/sites/{1}:{2}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, siteUri.Host, siteUri.AbsolutePath);
     var    siteInfo  = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }
예제 #23
0
 private static void GetSubSites(string token, string siteId)
 {
     string  webApiUrl    = string.Format("{0}/sites/{1}/sites", GraphAPIVersion.V1, siteId);
     dynamic siteInfo     = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
     var     subSiteCount = siteInfo.value.Count;
 }
예제 #24
0
 public static void UpdatePermissionById(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string itemId, string permissionId)
 {
     string  webApiUrl   = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/items/{5}/permissions/{6}", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, itemId, permissionId);
     var     requestBody = JsonConvert.SerializeObject(new { roles = new string[] { "read" } });
     dynamic result      = GraphApiCallHelper.PatchApiJObject(token, webApiUrl, requestBody);
 }
예제 #25
0
 private static void GetListsWithoutSystem(string token, string siteId)
 {
     string  webApiUrl    = string.Format("{0}/sites/{1}/lists", GraphAPIVersion.V1, siteId);
     dynamic allListsInfo = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
     var     subSiteCount = allListsInfo.value.Count;
 }
예제 #26
0
 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);
 }
예제 #27
0
 public static void Search(string token, string hostName, Guid siteCollectionId, Guid siteId, string driveId, string searchQuery)
 {
     string  webApiUrl = string.Format("{0}/sites/{1},{2},{3}/drives/{4}/root/search(q='{5}')", IsBeta ? GraphAPIVersion.BETA : GraphAPIVersion.V1, hostName, siteCollectionId, siteId, driveId, searchQuery);
     dynamic result    = GraphApiCallHelper.GetApiJObject(token, webApiUrl);
 }