/// <summary> /// Used to create a new empty folder. The new folder will be created inside of the specified parent folder /// </summary> /// <param name="folder"></param> /// <returns></returns> public async Task<BoxFolder> CreateAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Name.ThrowIfNullOrWhiteSpace("folderRequest.Name"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize<BoxFolderRequest>(folderRequest)); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }
/// <summary> /// Used to create a copy of a folder in another folder. The original version of the folder will not be altered. /// </summary> /// <returns></returns> public async Task<BoxFolder> CopyAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, string.Format(Constants.CopyPathString, folderRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
/// <summary> /// Used to update information about the folder. To move a folder, update the ID of its parent. To enable an /// email address that can be used to upload files to this folder, update the folder_upload_email attribute. /// An optional If-Match header can be included to ensure that client only updates the folder if it knows /// about the latest version. /// </summary> /// <returns></returns> public async Task<BoxFolder> UpdateInformationAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)) .Method(RequestMethod.Put); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <returns></returns> public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); folderRequest.Parent.ThrowIfNull("folderRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(folderRequest)) .Authorize(_auth.Session.AccessToken); IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request); return response.ResponseObject; }
/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in /// before it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same /// name in that parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <param name="folderRequest">BoxFolderRequest object (specify Parent.Id if you wish to restore to a different parent)</param> /// <param name="fields">Attribute(s) to include in the response</param> /// <returns>The full item will be returned if success. By default it is restored to the parent folder it was in before it was trashed.</returns> public async Task<BoxFolder> RestoreTrashedFolderAsync(BoxFolderRequest folderRequest, List<string> fields = null) { folderRequest.ThrowIfNull("folderRequest") .Id.ThrowIfNullOrWhiteSpace("folderRequest.Id"); BoxRequest request = new BoxRequest(_config.FoldersEndpointUri, folderRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields); // ID shall not be used in request body it is used only as url attribute string oldId = folderRequest.Id; folderRequest.Id = null; request.Payload(_converter.Serialize(folderRequest)); folderRequest.Id = oldId; IBoxResponse<BoxFolder> response = await ToResponseAsync<BoxFolder>(request).ConfigureAwait(false); return response.ResponseObject; }