Exemplo n.º 1
0
        public void ShellFileOperationTest()
        {
            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            String[] source = new String[3];
            String[] dest   = new String[3];

            source[0] = @"C:\TEMP\test.txt";
            source[1] = @"C:\TEMP\test1.txt";
            source[2] = @"C:\TEMP1";


            fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            //fo.OwnerWindow = this.Handle;
            fo.SourceFiles = source;
            fo.DestFiles   = dest;

            bool RetVal = fo.DoOperation();

            if (RetVal)
            {
                Trace.WriteLine("Copy Complete without errors!");
            }
            else
            {
                Trace.WriteLine("Copy Complete with errors!");
            }
        }
Exemplo n.º 2
0
        public void Move(List<FileSystemInfo> from, DirectoryInfo to)
        {
            string[] sFrom = FilesToStrings(from);
            string[] sTo = GetTargetPathes(from, to);

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
            fo.SourceFiles = sFrom;
            fo.DestFiles = sTo;
            fo.DoOperation();
        }
Exemplo n.º 3
0
        public void Move(List <FileSystemInfo> from, DirectoryInfo to)
        {
            string[] sFrom = FilesToStrings(from);
            string[] sTo   = GetTargetPathes(from, to);

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            fo.Operation   = ShellLib.ShellFileOperation.FileOperations.FO_MOVE;
            fo.SourceFiles = sFrom;
            fo.DestFiles   = sTo;
            fo.DoOperation();
        }
Exemplo n.º 4
0
        public void DeleteToRecycler(List<FileSystemInfo> from)
        {
            string[] sFrom = FilesToStrings(from);

            ShellFileOperation.ShellFileOperationFlags flags = ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION |
                ShellFileOperation.ShellFileOperationFlags.FOF_SILENT | ShellFileOperation.ShellFileOperationFlags.FOF_ALLOWUNDO;

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            fo.OperationFlags = flags;
            fo.Operation = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            fo.SourceFiles = sFrom;
            fo.DoOperation();
        }
Exemplo n.º 5
0
        public void DeleteToRecycler(List <FileSystemInfo> from)
        {
            string[] sFrom = FilesToStrings(from);

            ShellFileOperation.ShellFileOperationFlags flags = ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION |
                                                               ShellFileOperation.ShellFileOperationFlags.FOF_SILENT | ShellFileOperation.ShellFileOperationFlags.FOF_ALLOWUNDO;

            ShellLib.ShellFileOperation fo = new ShellLib.ShellFileOperation();

            fo.OperationFlags = flags;
            fo.Operation      = ShellLib.ShellFileOperation.FileOperations.FO_DELETE;
            fo.SourceFiles    = sFrom;
            fo.DoOperation();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copy one file using the Shell API. The progress dialog displayed is not modal.
        /// </summary>
        /// <param name="Sources">Source paths of the files to copy.</param>
        /// <param name="Destinations">Destination paths of the files to copy.</param>
        /// <param name="HideUiErrors">No user interface will be displayed if an error occurs.</param>
        /// <param name="SilentOverwrite">Do not prompt the user before overwritting the destination file. </param>
        /// <param name="RenameDestOnCollision">Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.</param>
        /// <param name="SimpleProgress">Displays a progress dialog box but does not show the file names.</param>
        /// <param name="Silent">Does not display a progress dialog box. </param>
        /// <param name="LockUI">Set to true if you want the entire application to be disabled during the operation.</param>
        /// <returns>True if the operation completed with success, false if the user aborted or if an error occured.</returns>
        public static ShellFileOperation.CopyFileResult CopyFiles(List<String> Sources,
            List<String> Destinations,
            bool HideUiErrors,
            bool SilentOverwrite,
            bool RenameDestOnCollision,
            bool SimpleProgress,
            bool Silent,
            bool LockUI,
            Control owner,
            ref String errorMessage)
        {
            // Prepare the Shell.
            ShellLib.ShellFileOperation FileOp = new ShellLib.ShellFileOperation();

            if (HideUiErrors)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NOERRORUI;

            if (RenameDestOnCollision)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_RENAMEONCOLLISION;

            if (SilentOverwrite)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_NOCONFIRMATION;

            if (SimpleProgress)
                FileOp.OperationFlags |= ShellLib.ShellFileOperation.ShellFileOperationFlags.FOF_SIMPLEPROGRESS;

            if (owner != null) FileOp.OwnerWindow = owner.Handle;
            FileOp.SourceFiles = Sources.ToArray();
            FileOp.DestFiles = Destinations.ToArray();

            // Disable the entire application while the copy is being done, if required.
            // Necessary since we can't make the progress dialog modal.
            try
            {
                if (LockUI) owner.Enabled = false;

                return FileOp.DoOperation(ref errorMessage);
            }

            finally
            {
                if (LockUI) owner.Enabled = true;
            }
        }