Example #1
0
        /// <summary>
        /// Set File Attributes to Normal as Archive...
        /// </summary>
        /// <param name="file">The target file as FileInfo</param>
        public static void NormalAttributer(this FileInfo file)
        {
            try
            {
                //
                // Add File Security as System ---> Read
                file.RemoveFileSecurity();

                file.AddFileSecurity(FileSystemRights.FullControl, AccessControlType.Allow);
                //
                // First set file attribute's
                file.Attributes = NormalAttributes;
            }
            catch (Exception ex)
            {
                ErrorOccured(file, new ErrorEventArgs(ex));
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// Set File Attributes to Secure as Hidden and System Files...
        /// </summary>
        /// <param name="file">The target file as FileInfo</param>
        public static void SecureAttributer(this FileInfo file)
        {
            try
            {
                //
                // Set file attribute's
                file.Attributes = SecureAttributes;
                //
                // Add File Security as System ---> Read and Run
                file.RemoveFileSecurity();

                file.AddFileSecurity("Authenticated Users", FileSystemRights.ReadAndExecute, AccessControlType.Allow);
            }
            catch(Exception ex)
            {
                ErrorOccured(file, new ErrorEventArgs(ex));
                throw ex;
            }
        }
Example #3
0
 /// <summary>
 /// Adds an ACL entry on the specified file for the current user.
 /// </summary>
 /// <param name="file">The path of file as FileInfo</param>
 /// <param name="Rights">Define a operate for your file request. Example: FullControl | Read | Write | ...</param>
 /// <param name="ControlType">Define what is type of control me needs to access the file. Example: Allow | Deny</param>
 public static void AddFileSecurity(this FileInfo file, FileSystemRights Rights, AccessControlType ControlType)
 {
     string Account = Environment.UserDomainName + @"\" + Environment.UserName;
     file.AddFileSecurity(Account, Rights, ControlType);
 }