public void CopyItem(string source, string destination, string newName)
 {
     ThrowIfDisposed();
     using var sourceItem      = CreateShellItem(source);
     using var destinationItem = CreateShellItem(destination);
     _fileOperation.CopyItem(sourceItem.Item, destinationItem.Item, newName, null);
 }
Example #2
0
        public void CopyItem(string source, string destination, string newName)
        {
            IShellItem sourceItem      = SafeNativeMethods.CreateShellItem(source);
            IShellItem destinationItem = SafeNativeMethods.CreateShellItem(destination);

            fileOperation.CopyItem(sourceItem, destinationItem, newName, null);
        }
Example #3
0
        public static void Copy(string destination, string source, bool overwrite = true)
        {
            if (Path.GetFullPath(destination)
                == Path.GetFullPath(source))
            {
                return;
            }

            if (_fileOperation == null)
            {
                System.IO.File.Copy(source, destination, overwrite);
            }
            else
            {
                if (!overwrite)
                {
                    destination = GetNonOverwriteFilename(destination);
                }

                var sourceItem          = CreateItem(source);
                var destinationPathItem = CreateItem(System.IO.Path.GetDirectoryName(destination));

                var result = _fileOperation.CopyItem(sourceItem, destinationPathItem,
                                                     Path.GetFileName(destination), IntPtr.Zero);

                Marshal.ReleaseComObject(destinationPathItem);
                Marshal.ReleaseComObject(sourceItem);

                AssertHresult(result);
            }
        }
 public void CopyItem(string source, string destination, string newName)
 {
     ThrowIfDisposed();
     using (ComReleaser <IShellItem> sourceItem = CreateShellItem(source))
         using (ComReleaser <IShellItem> destinationItem = CreateShellItem(destination)) {
             _fileOperation.CopyItem(sourceItem.Item, destinationItem.Item, newName, null);
         }
 }
        //public HResult MoveItems(object punkItems, IShellItem psiDestinationFolder) => throw new NotImplementedException();

        public void CopyItem(IShellItem psiItem, IShellItem psiDestinationFolder, string pszCopyName, FileOperationProgressSink pfopsItem)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(FileOperation));
            }

            HResult hr = fileOperation.CopyItem(psiItem, psiDestinationFolder, pszCopyName, pfopsItem?.FileOperationProgressSinkInternal);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
        }
Example #6
0
 /// <summary>
 /// Add a file copy operation to the queue.
 /// </summary>
 /// <param name="source">Full path and filename to copy from (must exist).</param>
 /// <param name="destPath">Full path without filename to copy to (must exist).</param>
 /// <param name="destFilename">Filename without path to copy to (will be created or overwritten).</param>
 public void Queue(string source, string destPath, string destFilename)
 {
     using ComDisposer <IShellItem> sourceItem      = _shellItemFactory.Create(source);
     using ComDisposer <IShellItem> destinationItem = _shellItemFactory.Create(destPath);
     _fileOperation.CopyItem(sourceItem.Value, destinationItem.Value, destFilename, null);
 }