コード例 #1
0
        /// <summary>
        /// This method creates and uploads a file into a parent folder
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="parentFolderId">The ID of the parent folder</param>
        /// <param name="file">The file object</param>
        /// <param name="content">The binary stream of the file content</param>
        /// <param name="contentType">The content type of the file</param>
        /// <returns>The just created and uploaded file object</returns>
        public static DriveItem UploadFile(String driveId, String parentFolderId,
                                           DriveItem file, Stream content, String contentType)
        {
            var jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}drives/{1}/items/{2}/children",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              parentFolderId),
                file,
                "application/json");

            var uploadedFile = JsonConvert.DeserializeObject <DriveItem>(jsonResponse);

            try
            {
                MicrosoftGraphHelper.MakePutRequest(
                    String.Format("{0}drives/{1}/items/{2}/content",
                                  MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                                  driveId,
                                  uploadedFile.Id),
                    content,
                    contentType);
            }
            catch (ApplicationException ex)
            {
                // For whatever reason we come here ... the upload failed
                // and we need to delete the just created file
                FilesHelper.DeleteFile(driveId, uploadedFile.Id);

                // And then we re-throw the exception
                throw ex;
            }

            return(uploadedFile);
        }
コード例 #2
0
        /// <summary>
        /// This method adds a new user to Azure AD
        /// </summary>
        /// <param name="user">The user to add</param>
        /// <returns>The just added user</returns>
        public static User AddUser(User user)
        {
            String jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}users",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri),
                user, "application/json");

            var addedUser = JsonConvert.DeserializeObject <User>(jsonResponse);

            return(addedUser);
        }
コード例 #3
0
        /// <summary>
        /// Creates/Adds a new Office 365 Group
        /// </summary>
        /// <param name="group">The group tp add/create</param>
        /// <returns>The just added group</returns>
        public static Group AddUnifiedGroup(Group group)
        {
            String jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}groups",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri),
                group, "application/json");

            var addedGroup = JsonConvert.DeserializeObject <Group>(jsonResponse);

            return(addedGroup);
        }
コード例 #4
0
        /// <summary>
        /// This method adds a contact
        /// </summary>
        /// <param name="contact">The contact to add</param>
        /// <returns>The added contact</returns>
        public static Contact AddContact(Contact contact)
        {
            String jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}me/contacts",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri),
                contact,
                "application/json");

            var addedContact = JsonConvert.DeserializeObject <Contact>(jsonResponse);

            return(addedContact);
        }
コード例 #5
0
        /// <summary>
        /// This method creates an event in a target calendar
        /// </summary>
        /// <param name="calendarId">The ID of the target calendar</param>
        /// <param name="calendarEvent">The event to add</param>
        /// <returns>The added event</returns>
        public static Event CreateEvent(String calendarId, Event calendarEvent)
        {
            String jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}me/calendars/{1}/events",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              calendarId),
                calendarEvent, "application/json");

            var createdEvent = JsonConvert.DeserializeObject <Event>(jsonResponse);

            return(createdEvent);
        }
コード例 #6
0
        /// <summary>
        /// This method adds a new permission to a target DriveItem
        /// </summary>
        /// <param name="driveItemId">The ID of the DriveItem</param>
        /// <param name="permission">The permission to add</param>
        /// <returns>The just added permission object</returns>
        public static Permission AddDriveItemPermission(String driveItemId, Permission permission)
        {
            var jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}me/drive/items/{1}/permissions",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveItemId),
                permission,
                "application/json"
                );

            var addedPermission = JsonConvert.DeserializeObject <Permission>(jsonResponse);

            return(addedPermission);
        }
コード例 #7
0
        /// <summary>
        /// This method creates a new folder in OneDrive for Business
        /// </summary>
        /// <param name="driveId">The ID of the target drive</param>
        /// <param name="parentFolderId">The ID of the parent folder</param>
        /// <param name="folder">The new folder object to create</param>
        /// <returns>The just created folder</returns>
        public static DriveItem CreateFolder(String driveId, String parentFolderId, DriveItem folder)
        {
            var jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}drives/{1}/items/{2}/children",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveId,
                              parentFolderId),
                folder,
                "application/json");

            var newFolder = JsonConvert.DeserializeObject <DriveItem>(jsonResponse);

            return(newFolder);
        }
コード例 #8
0
        /// <summary>
        /// This method creates a sharing link for a target DriveItem
        /// </summary>
        /// <param name="driveItemId">The ID of the DriveItem</param>
        /// <param name="type">The type of the sharing link</param>
        /// <param name="scope">The scope of the sharing link</param>
        /// <returns>The just added permission for the sharing link</returns>
        public static Permission CreateSharingLink(String driveItemId, SharingLinkType type, SharingLinkScope scope)
        {
            var jsonResponse = MicrosoftGraphHelper.MakePostRequestForString(
                String.Format("{0}me/drive/items/{1}/microsoft.graph.createLink",
                              MicrosoftGraphHelper.MicrosoftGraphV1BaseUri,
                              driveItemId),
                new {
                @type  = type.ToString().ToLower(),
                @scope = scope.ToString().ToLower(),
            },
                "application/json"
                );

            var addedPermission = JsonConvert.DeserializeObject <Permission>(jsonResponse);

            return(addedPermission);
        }