public bool InvokeOperation(IntPtr?ownerWindow = null, FileOperations operation = FileOperations.Copy, String[] sourceFiles = null, String[] destinationFiles = null) { if (!ownerWindow.HasValue || ownerWindow.Value == null) { ownerWindow = IntPtr.Zero; } Connection.Native.ShellFileOperation shellFileOperation = new Connection.Native.ShellFileOperation { hwnd = ownerWindow.Value, wFunc = (uint)operation }; string multiSource = this.StringArrayToMultiString(sourceFiles); string multiDest = this.StringArrayToMultiString(destinationFiles); shellFileOperation.pFrom = Marshal.StringToHGlobalUni(multiSource); shellFileOperation.pTo = Marshal.StringToHGlobalUni(multiDest); shellFileOperation.fFlags = (ushort)this.operationFlags; shellFileOperation.lpszProgressTitle = this.progressTitle; shellFileOperation.fAnyOperationsAborted = 0; shellFileOperation.hNameMappings = IntPtr.Zero; int retVal = WindowsApi.SHFileOperation(ref shellFileOperation); WindowsApi.SHChangeNotify(/* ShellChangeNotificationEvents.SHCNE_ALLEVENTS = */ 0x7FFFFFFF /* All events have occurred. */, /* ShellChangeNotificationFlags.SHCNF_DWORD = */ 0x0003 /*The dwItem1 and dwItem2 parameters are DWORD values. */, IntPtr.Zero, IntPtr.Zero); if (retVal != 0) { return(false); } if (shellFileOperation.fAnyOperationsAborted != 0) { return(false); } return(true); }
public bool InvokeOperation(IntPtr? ownerWindow = null, FileOperations operation = FileOperations.Copy, String[] sourceFiles = null, String[] destinationFiles = null) { if (!ownerWindow.HasValue || ownerWindow.Value == null) ownerWindow = IntPtr.Zero; Connection.Native.ShellFileOperation shellFileOperation = new Connection.Native.ShellFileOperation { hwnd = ownerWindow.Value, wFunc = (uint)operation }; string multiSource = this.StringArrayToMultiString(sourceFiles); string multiDest = this.StringArrayToMultiString(destinationFiles); shellFileOperation.pFrom = Marshal.StringToHGlobalUni(multiSource); shellFileOperation.pTo = Marshal.StringToHGlobalUni(multiDest); shellFileOperation.fFlags = (ushort) this.operationFlags; shellFileOperation.lpszProgressTitle = this.progressTitle; shellFileOperation.fAnyOperationsAborted = 0; shellFileOperation.hNameMappings = IntPtr.Zero; int retVal = WindowsApi.SHFileOperation(ref shellFileOperation); WindowsApi.SHChangeNotify(/* ShellChangeNotificationEvents.SHCNE_ALLEVENTS = */ 0x7FFFFFFF /* All events have occurred. */,/* ShellChangeNotificationFlags.SHCNF_DWORD = */ 0x0003 /*The dwItem1 and dwItem2 parameters are DWORD values. */,IntPtr.Zero,IntPtr.Zero); if (retVal != 0) return false; if (shellFileOperation.fAnyOperationsAborted != 0) return false; return true; }