Box.V2.Managers.BoxFilesManager.CopyAsync C# (CSharp) Method

CopyAsync() public method

Used to create a copy of a file in another folder. The original version of the file will not be altered.
public CopyAsync ( Box.V2.Models.BoxFileRequest fileRequest, List fields = null ) : Task
fileRequest Box.V2.Models.BoxFileRequest BoxFileRequest object.
fields List Attribute(s) to include in the response.
return Task
        public async Task<BoxFile> CopyAsync(BoxFileRequest fileRequest, List<string> fields = null)
        {
            fileRequest.ThrowIfNull("fileRequest");
            fileRequest.Id.ThrowIfNullOrWhiteSpace("fileRequest.Id");
            fileRequest.Parent.ThrowIfNull("fileRequest.Parent")
                .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id");

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id))
                .Method(RequestMethod.Post)
                .Param(ParamFields, fields);

            fileRequest.Id = null; //file Id was used as a query parameter in this case
            request.Payload(_converter.Serialize(fileRequest));

            IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }