public SHFileOperationAPI()
 {
     fFlags        = new FILEOP_FLAGS();
     _ShFile       = new SHFILEOPSTRUCT();
     _ShFile.hwnd  = IntPtr.Zero;
     _ShFile.wFunc = FO_Func.FO_COPY;
     _ShFile.pFrom = "";
     _ShFile.pTo   = "";
     _ShFile.fAnyOperationsAborted = 0;
     _ShFile.hNameMappings         = IntPtr.Zero;
     _ShFile.lpszProgressTitle     = "";
 }
 public InteropSHFileOperation()
 {
     this.fFlags        = new FILEOP_FLAGS();
     this._ShFile       = new SHFILEOPSTRUCT();
     this._ShFile.hwnd  = IntPtr.Zero;
     this._ShFile.wFunc = FO_Func.FO_COPY;
     this._ShFile.pFrom = "";
     this._ShFile.pTo   = "";
     this._ShFile.fAnyOperationsAborted = false;
     this._ShFile.hNameMappings         = IntPtr.Zero;
     this._ShFile.lpszProgressTitle     = "";
 }
 public SHFileOperationAPI(string pFrom, string pTo)
 {
     this.fFlags        = new FILEOP_FLAGS();
     this._ShFile       = new SHFILEOPSTRUCT();
     this._ShFile.hwnd  = IntPtr.Zero;
     this._ShFile.wFunc = FO_Func.FO_COPY;
     this._ShFile.pFrom = pFrom;
     this._ShFile.pTo   = pTo;
     this._ShFile.fAnyOperationsAborted = 0;
     this._ShFile.hNameMappings         = IntPtr.Zero;
     this._ShFile.lpszProgressTitle     = "";
 }
        public bool Execute()
        {
            this._ShFile.fFlags = this.fFlags.Flag;
            int returnValue = SHFileOperation(ref this._ShFile);

            if (returnValue == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public static int TransferFileUsingSystem(List <string> from, string to, bool isMove = false, bool showAlert = true)
        {
            if (from == null || from.Count <= 0 || to == null || string.IsNullOrEmpty(to))
            {
                return(-1);
            }

            string fromStr = "";
            string toStr   = "";

            foreach (var file in from)
            {
                fromStr += file + "\0";
            }

            toStr = to + "\0";

            if (string.IsNullOrEmpty(fromStr) || string.IsNullOrEmpty(toStr))
            {
                return(-2);
            }

            FILEOP_FLAGS flags = Win32.FILEOP_FLAGS.FOF_FILESONLY | Win32.FILEOP_FLAGS.FOF_ALLOWUNDO;

            if (!showAlert)
            {
                flags |= Win32.FILEOP_FLAGS.FOF_RENAMEONCOLLISION;
                flags |= Win32.FILEOP_FLAGS.FOF_NOCONFIRMATION;
            }

            Win32.SHFILEOPSTRUCT op = new Win32.SHFILEOPSTRUCT();
            op.hwnd                  = IntPtr.Zero;
            op.wFunc                 = isMove ? FileFuncFlags.FO_MOVE : FileFuncFlags.FO_COPY;
            op.pFrom                 = fromStr;
            op.pTo                   = toStr;
            op.hNameMappings         = IntPtr.Zero;
            op.fFlags                = flags;
            op.fAnyOperationsAborted = false;
            int ret = Win32.SHFileOperation(ref op);

            return(ret);
        }
		public InteropSHFileOperation()
		{

			this.fFlags = new FILEOP_FLAGS();
			this._ShFile = new SHFILEOPSTRUCT();
			this._ShFile.hwnd = IntPtr.Zero;
			this._ShFile.wFunc = FO_Func.FO_COPY;
			this._ShFile.pFrom = "";
			this._ShFile.pTo = "";
			this._ShFile.fAnyOperationsAborted = 0;
			this._ShFile.hNameMappings = IntPtr.Zero;
			this._ShFile.lpszProgressTitle = "";

		}
		public bool Execute()
		{
			this._ShFile.fFlags = this.fFlags.Flag;
			int ReturnValue = SHFileOperation(ref this._ShFile);
			if (ReturnValue == 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
Example #8
0
 public int Execute()
 {
     this._ShFile.fFlags = this.fFlags.Flag;
     return(SHFileOperation(ref this._ShFile));
 }
Example #9
0
 public bool Execute()
 {
     this._ShFile.fFlags = this.fFlags.Flag;
     return SHFileOperation(ref this._ShFile) == 0;//true if no errors
 }
Example #10
0

        
Example #11
0
        /// <summary>
        /// Move/Copy/Rename files
        /// </summary>
        /// <param name="operation">Shell operation to perform</param>
        /// <param name="srcpath">Source file(s)</param>
        /// <param name="destpath">Destination file(s) - must match the number of source files</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static Task SHFileOperationAsync(FileOperation operation, string[] srcfiles, string[] destfiles, FILEOP_FLAGS flags = DEFAULT_FLAGS)
        {
            var src  = String.Concat(srcfiles.Select(f => f + '\0'));
            var dest = String.Concat(destfiles.Select(f => f + '\0'));

            flags |= FILEOP_FLAGS.FOF_MULTIDESTFILES; // Dest is a 1:1 mapping of src, instead of a directory

            return(SHFileOperationAsync(operation, src, dest, flags));
        }
Example #12
0
        /// <summary>
        /// Move/Copy files to a destination directory
        /// </summary>
        /// <param name="operation">Shell operation to perform</param>
        /// <param name="srcpath">Source file(s)</param>
        /// <param name="destpath">Destination directory</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static Task SHFileOperationAsync(FileOperation operation, string[] srcfiles, string destdir, FILEOP_FLAGS flags = DEFAULT_FLAGS)
        {
            var src = String.Concat(srcfiles.Select(f => f + '\0'));

            return(SHFileOperationAsync(operation, src, destdir, flags));
        }
Example #13
0
        /// <summary>
        /// Move/Copy a directory to destination directory
        /// </summary>
        /// <remarks>
        /// If you pass a file in srcpath, it may or may not be treated as a directory.
        /// To remove ambiguity you should use one of the other overloads that take a string[].
        /// </remarks>
        /// <param name="operation">Shell operation to perform</param>
        /// <param name="srcpath">Source file or directory</param>
        /// <param name="destpath">Destination directory</param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static Task SHFileOperationAsync(FileOperation operation, string srcpath, string destpath, FILEOP_FLAGS flags = DEFAULT_FLAGS)
        {
            return(Task.Factory.StartNew(() =>
            {
                SHFILEOPSTRUCT fFileOpStruct = new SHFILEOPSTRUCT
                {
                    hwnd = IntPtr.Zero,
                    wFunc = operation,
                    pFrom = srcpath,
                    pTo = destpath,
                    fFlags = flags,
                    fAnyOperationsAborted = false,
                    hNameMappings = IntPtr.Zero,
                    lpszProgressTitle = null
                };

                int hr = SHFileOperation(ref fFileOpStruct);

                // The error code is a standard Win32 error, with the exception of a handful of codes which mean specific things.
                // See https://msdn.microsoft.com/en-us/library/bb762164(v=vs.85).aspx for more info.
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // You can check fFileOpStruct.fAnyOperationsAborted to check if any operations were aborted
            }, TaskCreationOptions.LongRunning));
        }
        public ShellFileOperation()
        {

            fFlags = new FILEOP_FLAGS();
            _ShFile = new SHFILEOPSTRUCT();
            _ShFile.hwnd = IntPtr.Zero;
            _ShFile.wFunc = FO_Func.FO_COPY;
            _ShFile.pFrom = "";
            _ShFile.pTo = "";
            _ShFile.fAnyOperationsAborted = false;
            _ShFile.hNameMappings = IntPtr.Zero;
            _ShFile.lpszProgressTitle = "";

        }