Example #1
0
        public static void Delete(string strFilePath, bool blnRenameOnFail)
        {
            bool blnFileExists = FileManager.Exists(strFilePath);

            if (blnFileExists == false)
            {
                return;
            }

            Exception objActiveException = null;

            try
            {
                FileAttributes enuFileAttributes = FileManager.GetAttributes(strFilePath);
                if ((enuFileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    FileManager.SetAttributes(strFilePath, FileAttributes.Normal);
                }
            }
            catch (Exception objException)
            {
                objActiveException = objException;
            }

            if (objActiveException == null)
            {
                try
                {
                    File.Delete(strFilePath);
                    OnFileDeleted(strFilePath);
                }
                catch (Exception objException)
                {
                    objActiveException = objException;
                }
            }

            if ((objActiveException != null) && (blnRenameOnFail == true))
            {
                objActiveException = null;

                string strRenameFilePath = CreateDeleteFileName(strFilePath);

                try
                {
                    File.Move(strFilePath, strRenameFilePath);
                    OnDeletedFileRenamed(strFilePath, strRenameFilePath);
                }
                catch (Exception objException)
                {
                    string strErrorMessage = "Error while attempting to rename (move) file '" + strFilePath + "' for deletion:\r\n";
                    objActiveException = new Exception(strErrorMessage, objException);
                }
            }

            if (objActiveException != null)
            {
                throw objActiveException;
            }
        }
Example #2
0
 public static FileAttributes GetAttributes(string strFilePath)
 {
     return(FileManager.GetAttributes(strFilePath, FileAttributes.Normal));
 }