Example #1
0
        public async Task <IFile> MoveAsync(string newPath, CollisionOption collisionOption = CollisionOption.ReplaceExisting,
                                            CancellationToken cancellationToken             = new CancellationToken())
        {
            var newFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(newPath))
                            .AsTask(cancellationToken)
                            .ConfigureAwait(false);

            string newName = System.IO.Path.GetFileName(newPath);

            try
            {
                await _storageFile.MoveAsync(newFolder, newName, collisionOption.ToNameCollisionOption())
                .AsTask(cancellationToken)
                .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (ex.HResult == FileAlreadyExists)
                {
                    throw new UnifiedIOException(string.Format("The file {0} already exists", newPath), ex);
                }

                throw new UnifiedIOException(
                          string.Format("Could not move the file {0} to {1}: {2}", _path, newPath, ex.Message), ex);
            }

            _path = _storageFile.Path;
            return(this);
        }
Example #2
0
 public static async Task MoveFile(IStorageFile file, IStorageFolder destinationDirectory, string newName)
 {
     if (file != null && destinationDirectory != null && !string.IsNullOrWhiteSpace(newName))
     {
         await file.MoveAsync(destinationDirectory, newName, NameCollisionOption.ReplaceExisting);
     }
 }
Example #3
0
        /// <summary>
        /// Moves a file.
        /// </summary>
        /// <param name="newPath">The new full path of the file.</param>
        /// <param name="collisionOption">How to deal with collisions with existing files.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task which will complete after the file is moved.
        /// </returns>
        public async Task MoveAsync(string newPath, NameCollisionOption collisionOption, CancellationToken cancellationToken)
        {
            Requires.NotNullOrEmpty(newPath, "newPath");

            var newFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(newPath)).AsTask(cancellationToken).ConfigureAwait(false);

            string newName = System.IO.Path.GetFileName(newPath);

            try
            {
                await _wrappedFile.MoveAsync(newFolder, newName, (Windows.Storage.NameCollisionOption) collisionOption).AsTask(cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                if (ex.HResult == FILE_ALREADY_EXISTS)
                {
                    throw new IOException("File already exists.", ex);
                }

                throw;
            }
        }
Example #4
0
 public static async Task MoveFile(IStorageFile file, IStorageFolder destinationDirectory, string newName)
 {
     if (file != null && destinationDirectory != null && !string.IsNullOrWhiteSpace(newName))
     {
         await file.MoveAsync(destinationDirectory, newName, NameCollisionOption.ReplaceExisting);
     }
 }