/// <summary>
 /// Create a new FileOperation object that will perform all queued operations when disposed.
 /// </summary>
 /// <param name="owner">Owner of the file operations</param>
 public FileOperation(IWin32Window owner)
 {
     _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);
       _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
       if(owner != null)
     _fileOperation.SetOwnerWindow((uint)owner.Handle);
 }
    public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner) {
      _callbackSink = callbackSink;
      _fileOperation = (IFileOperation) Activator.CreateInstance(_fileOperationType);

      _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
      if (_callbackSink != null) SinkCookie = _fileOperation.Advise(_callbackSink);
      if (owner != null) _fileOperation.SetOwnerWindow((uint) owner.Handle);
    }
        private static IFileOperation CreateAndInitializeFileOperation()
        {
            // Create the IFileOperation object
            var pfo = new IFileOperation();

            // Set the operation flags. Turn off all UI from being shown to the user during the operation. This includes error, confirmation
            // and progress dialogs.
            pfo.SetOperationFlags(FILEOP_FLAGS.FOF_SILENT | FILEOP_FLAGS.FOF_NOCONFIRMATION | FILEOP_FLAGS.FOF_NOERRORUI | FILEOP_FLAGS.FOF_NOCONFIRMMKDIR);
            return(pfo);
        }
Exemple #4
0
 /// <summary>
 /// Create a new FileOperation object that will perform all queued operations when disposed.
 /// </summary>
 /// <param name="owner">Owner of the file operations.</param>
 public CopyFilesOperation(IWin32Window owner)
 {
     _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);
     _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
     if (owner != null)
     {
         _fileOperation.SetOwnerWindow((uint)owner.Handle);
     }
     _shellItemFactory = new ShellItemFactory();
 }
        public FileOperation(FileOperationProgressSink callbackSink, IWin32Window owner)
        {
            _callbackSink  = callbackSink;
            _fileOperation = (IFileOperation)Activator.CreateInstance(_fileOperationType);

            _fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
            if (_callbackSink != null)
            {
                SinkCookie = _fileOperation.Advise(_callbackSink);
            }
            if (owner != null)
            {
                _fileOperation.SetOwnerWindow((uint)owner.Handle);
            }
        }
Exemple #6
0
        public static bool Begin(bool undoable = true)
        {
            if (_fileOperation != null)
            {
                throw new InvalidOperationException();
            }

            try
            {
                _fileOperation = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("3ad05575-8857-4850-9277-11b85bdb8e09"))) as IFileOperation;
                _fileOperation?.SetOperationFlags(
                    (undoable ? OperationFlag.AllowUndo : OperationFlag.None)
                    | OperationFlag.NoUI);
            }
            catch { return(false); }

            return(_fileOperation != null);
        }
        /// <summary>
        /// Sets parameters for the current operation.
        /// </summary>
        /// <param name="dwOperationFlags">Flags that control the file operation. FOF flags are defined in Shellapi.h and FOFX flags are defined in Shobjidl.h. Note : If this method is not called, the default value used by the operation is <see cref=" ShellOperationFlags.FOF_ALLOWUNDO"/> | <see cref="ShellOperationFlags.FOF_NOCONFIRMMKDIR"/>.</param>
        /// <remarks>Set these flags before you call <see cref="PerformOperations"/> to define the parameters for whatever operations are being performed, such as copy, delete, or rename.</remarks>
        /// <exception cref="ObjectDisposedException">Exception thrown when this object is disposed.</exception>
        /// <exception cref="PlatformNotSupportedException">Exception thrown when a requested flag is not supported by the current platform.</exception>
        /// <exception cref="Win32Exception">Exception thrown when this method fails because of an error in the Win32 COM API implementation.</exception>
        public void SetOperationFlags(ShellOperationFlags dwOperationFlags)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(FileOperation));
            }

            switch (dwOperationFlags)

            {
            case ShellOperationFlags.AddUndoRecord:
            case ShellOperationFlags.RecycleOnDelete:

                CoreHelpers.ThrowIfNotWin8();

                break;

            case ShellOperationFlags.CopyAsDownload:
            case ShellOperationFlags.DoNotDisplayLocations:

                CoreHelpers.ThrowIfNotWin7();

                break;

            case ShellOperationFlags.RequireElevation:

                CoreHelpers.ThrowIfNotVista();

                break;
            }

            HResult hr = fileOperation.SetOperationFlags(dwOperationFlags);

            if (!CoreErrorHelper.Succeeded(hr))
            {
                Marshal.ThrowExceptionForHR((int)hr);
            }
        }
 public void SetOperationFlags(FileOperationFlags operationFlags)
 {
     _fileOperation.SetOperationFlags(operationFlags);
 }
 public void AllowUndo()
 {
     fileOperation.SetOperationFlags(FileOperationFlags.FOF_ALLOWUNDO);
 }
 public FileOperation()
 {
     fileOperation = (IFileOperation)Activator.CreateInstance(fileOperationType);
     fileOperation.SetOperationFlags(FileOperationFlags.FOF_NOCONFIRMMKDIR);
     fileOperation.SetOwnerWindow(SafeNativeMethods.GetActiveWindowHandle());
 }
 public void AllowUndo()
 {
     fileOperation.SetOperationFlags(FILEOP_FLAGS.FOF_ALLOWUNDO);
 }
 public FileOperation()
 {
     fileOperation = (IFileOperation)Activator.CreateInstance(typeof(CFileOperations));
     fileOperation.SetOperationFlags(FILEOP_FLAGS.FOF_NOCONFIRMMKDIR);
     fileOperation.SetOwnerWindow(SafeNativeMethods.GetActiveWindowHandle());
 }