예제 #1
0
 static void OnFileRemoving(FileCancelEventArgs e)
 {
     if (FileRemoving != null)
     {
         FileRemoving(null, e);
     }
 }
예제 #2
0
        /// <summary>
        /// Fires the event handlers for a file being created.
        /// </summary>
        /// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param>
        /// <param name="isDirectory">Set to true if this is a directory</param>
        public static bool FireFileReplacing(string fileName, bool isDirectory)
        {
            FileCancelEventArgs e = new FileCancelEventArgs(fileName, isDirectory);

            if (FileReplacing != null)
            {
                FileReplacing(null, e);
            }
            return(!e.Cancel);
        }
예제 #3
0
        /// <summary>
        /// Removes a file, raising the appropriate events. This method may show message boxes.
        /// </summary>
        public static void RemoveFile(string fileName, bool isDirectory)
        {
            FileCancelEventArgs eargs = new FileCancelEventArgs(fileName, isDirectory);

            OnFileRemoving(eargs);
            if (eargs.Cancel)
            {
                return;
            }
            if (!eargs.OperationAlreadyDone)
            {
                if (isDirectory)
                {
                    try {
                        if (Directory.Exists(fileName))
                        {
                            if (DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                Directory.Delete(fileName, true);
                            }
                        }
                    } catch (Exception e) {
                        MessageService.ShowHandledException(e, "Can't remove directory " + fileName);
                    }
                }
                else
                {
                    try {
                        if (File.Exists(fileName))
                        {
                            if (DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                File.Delete(fileName);
                            }
                        }
                    } catch (Exception e) {
                        MessageService.ShowHandledException(e, "Can't remove file " + fileName);
                    }
                }
            }
            OnFileRemoved(new FileEventArgs(fileName, isDirectory));
        }