Click here to Skip to main content
Click here to Skip to main content

Testing File Access Rights in .NET 2.0

, 13 Jul 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple way to test individual access rights for a given file and user
Coder

Introduction

The purpose of this class is to provide a simple answer to a common question, "Do I have permission to Read or Write this file?".

The code was developed for a Web based configuration utility. Knowing in advance if write access was available is helpful and a bit nicer than simply throwing an exception.

To use it, simply instantiate one with the path and an optional user and you can use the accessors to determine if you have the access you need.

UserFileAccessRights rights = new UserFileAccessRights(txtLogPath.Text);
 if (rights.canWrite() && rights.canRead()) {
     lblLogMsg.Text = "R/W access";
 } else {
     if (rights.canWrite()) {
        lblLogMsg.Text = "Only Write access";
     } else if (rights.canRead()) {
         lblLogMsg.Text = "Only Read access";
     } else {
         lblLogMsg.CssClass = "error";
         lblLogMsg.Text = rights.ToString()
     }
 }

A check is done to see if a deny rule is found at the user level and the groups one level up.

One could recursively check groups and provide more detail with respect to inheritance so feel free to modify as you wish.

using System;
using System.Security;
using System.Security.AccessControl;
using System.Security.Principal;

namespace GCAWeb.Utils{

    /// <span class="code-SummaryComment"><summary></span>
    /// Configuring a Web site through a Web interface can be tricky. 
    /// If one is to read and write various files, it is useful to know 
    /// in advance if you have the authority to do so.
    /// 
    /// This class contains a simple answer to a 
    /// potentially complicated question 
    /// "Can I read this file or can I write to this file?"
    /// 
    /// Using the "rule of least privilege", 
    /// one must check not only is access granted but 
    /// is it denied at any point including a possibly recursive check of groups.
    /// 
    /// For this simple check, a look at the user and immediate groups are only checked.
    /// 
    /// This class could be expanded to identify if the applicable allow/deny rule
    /// was explicit or inherited
    /// 
    /// <span class="code-SummaryComment"></summary></span>
    public class UserFileAccessRights {

        private string _path;
        private System.Security.Principal.WindowsIdentity _principal;

        private bool _denyAppendData = false;
        private bool _denyChangePermissions = false;
        private bool _denyCreateDirectories = false;
        private bool _denyCreateFiles = false;
        private bool _denyDelete = false;
        private bool _denyDeleteSubdirectoriesAndFiles = false;
        private bool _denyExecuteFile = false;
        private bool _denyFullControl = false;
        private bool _denyListDirectory = false;
        private bool _denyModify = false;
        private bool _denyRead = false;
        private bool _denyReadAndExecute = false;
        private bool _denyReadAttributes = false;
        private bool _denyReadData = false;
        private bool _denyReadExtendedAttributes = false;
        private bool _denyReadPermissions = false;
        private bool _denySynchronize = false;
        private bool _denyTakeOwnership = false;
        private bool _denyTraverse = false;
        private bool _denyWrite = false;
        private bool _denyWriteAttributes = false;
        private bool _denyWriteData = false;
        private bool _denyWriteExtendedAttributes = false;

        private bool _allowAppendData = false;
        private bool _allowChangePermissions = false;
        private bool _allowCreateDirectories = false;
        private bool _allowCreateFiles = false;
        private bool _allowDelete = false;
        private bool _allowDeleteSubdirectoriesAndFiles = false;
        private bool _allowExecuteFile = false;
        private bool _allowFullControl = false;
        private bool _allowListDirectory = false;
        private bool _allowModify = false;
        private bool _allowRead = false;
        private bool _allowReadAndExecute = false;
        private bool _allowReadAttributes = false;
        private bool _allowReadData = false;
        private bool _allowReadExtendedAttributes = false;
        private bool _allowReadPermissions = false;
        private bool _allowSynchronize = false;
        private bool _allowTakeOwnership = false;
        private bool _allowTraverse = false;
        private bool _allowWrite = false;
        private bool _allowWriteAttributes = false;
        private bool _allowWriteData = false;
        private bool _allowWriteExtendedAttributes = false;

        public bool canAppendData() { return !_denyAppendData&&_allowAppendData; }
        public bool canChangePermissions() 
            { return !_denyChangePermissions&&_allowChangePermissions; }
        public bool canCreateDirectories() 
            { return !_denyCreateDirectories&&_allowCreateDirectories; }
        public bool canCreateFiles() { return !_denyCreateFiles&&_allowCreateFiles; }
        public bool canDelete() { return !_denyDelete && _allowDelete; }
        public bool canDeleteSubdirectoriesAndFiles() 
            { return !_denyDeleteSubdirectoriesAndFiles && 
                _allowDeleteSubdirectoriesAndFiles; }
        public bool canExecuteFile() { return !_denyExecuteFile && _allowExecuteFile; }
        public bool canFullControl() { return !_denyFullControl && _allowFullControl; }
        public bool canListDirectory() 
            { return !_denyListDirectory && _allowListDirectory; }
        public bool canModify() { return !_denyModify && _allowModify; }
        public bool canRead() { return !_denyRead && _allowRead; }
        public bool canReadAndExecute() 
            { return !_denyReadAndExecute && _allowReadAndExecute; }
        public bool canReadAttributes() 
            { return !_denyReadAttributes && _allowReadAttributes; }
        public bool canReadData() { return !_denyReadData && _allowReadData; }
        public bool canReadExtendedAttributes() 
            { return !_denyReadExtendedAttributes && 
                _allowReadExtendedAttributes; }
        public bool canReadPermissions() 
            { return !_denyReadPermissions && _allowReadPermissions; }
        public bool canSynchronize() { return !_denySynchronize && _allowSynchronize; }
        public bool canTakeOwnership() 
            { return !_denyTakeOwnership && _allowTakeOwnership; }
        public bool canTraverse() { return !_denyTraverse && _allowTraverse; }
        public bool canWrite() { return !_denyWrite && _allowWrite; }
        public bool canWriteAttributes() 
            { return !_denyWriteAttributes && _allowWriteAttributes; }
        public bool canWriteData() { return !_denyWriteData && _allowWriteData; }
        public bool canWriteExtendedAttributes() 
            { return !_denyWriteExtendedAttributes && 
                _allowWriteExtendedAttributes; }

        /// <span class="code-SummaryComment"><summary></span>
        /// Simple accessor
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public System.Security.Principal.WindowsIdentity getWindowsIdentity() {
            return _principal;
        }
        /// <span class="code-SummaryComment"><summary></span>
        /// Simple accessor
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public String getPath() {
            return _path;
        }

        /// <span class="code-SummaryComment"><summary></span>
        /// Convenience constructor assumes the current user
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="path"></param></span>
        public UserFileAccessRights(string path) :
            this(path, System.Security.Principal.WindowsIdentity.GetCurrent()){}


        /// <span class="code-SummaryComment"><summary></span>
        /// Supply the path to the file or directory and a user or group. 
        /// Access checks are done
        /// during instantiation to ensure we always have a valid object
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="path"></param></span>
        /// <span class="code-SummaryComment"><param name="principal"></param></span>
        public UserFileAccessRights(string path, 
            System.Security.Principal.WindowsIdentity principal) {
            this._path = path;
            this._principal = principal;
                        
            try {
                System.IO.FileInfo fi = new System.IO.FileInfo(_path);
                AuthorizationRuleCollection acl = fi.GetAccessControl().GetAccessRules
                            (true, true, typeof(SecurityIdentifier));
                for (int i = 0; i < acl.Count; i++) {
                    System.Security.AccessControl.FileSystemAccessRule rule = 
                           (System.Security.AccessControl.FileSystemAccessRule)acl[i];
                    if (_principal.User.Equals(rule.IdentityReference)) {
                        if (System.Security.AccessControl.AccessControlType.Deny.Equals
                                (rule.AccessControlType)) {
                            if (contains(FileSystemRights.AppendData,rule)) 
                                  _denyAppendData = true;
                            if (contains(FileSystemRights.ChangePermissions,rule)) 
                                  _denyChangePermissions = true;
                            if (contains(FileSystemRights.CreateDirectories,rule)) 
                                  _denyCreateDirectories = true;
                            if (contains(FileSystemRights.CreateFiles,rule)) 
                                  _denyCreateFiles = true;
                            if (contains(FileSystemRights.Delete,rule)) 
                                  _denyDelete = true;
                            if (contains(FileSystemRights.DeleteSubdirectoriesAndFiles,
                                   rule)) _denyDeleteSubdirectoriesAndFiles = true;
                            if (contains(FileSystemRights.ExecuteFile,rule)) 
                                  _denyExecuteFile = true;
                            if (contains(FileSystemRights.FullControl,rule)) 
                                  _denyFullControl = true;
                            if (contains(FileSystemRights.ListDirectory,rule)) 
                                  _denyListDirectory = true;
                            if (contains(FileSystemRights.Modify,rule)) 
                                  _denyModify = true;
                            if (contains(FileSystemRights.Read,rule)) _denyRead = true;
                            if (contains(FileSystemRights.ReadAndExecute,rule)) 
                                  _denyReadAndExecute = true;
                            if (contains(FileSystemRights.ReadAttributes,rule)) 
                                  _denyReadAttributes = true;
                            if (contains(FileSystemRights.ReadData,rule)) 
                                  _denyReadData = true;
                            if (contains(FileSystemRights.ReadExtendedAttributes,rule)) 
                                  _denyReadExtendedAttributes = true;
                            if (contains(FileSystemRights.ReadPermissions,rule)) 
                                  _denyReadPermissions = true;
                            if (contains(FileSystemRights.Synchronize,rule)) 
                                  _denySynchronize = true;
                            if (contains(FileSystemRights.TakeOwnership,rule)) 
                                  _denyTakeOwnership = true;
                            if (contains(FileSystemRights.Traverse,rule)) 
                                  _denyTraverse = true;
                            if (contains(FileSystemRights.Write,rule)) _denyWrite = true;
                            if (contains(FileSystemRights.WriteAttributes,rule)) 
                                  _denyWriteAttributes = true;
                            if (contains(FileSystemRights.WriteData,rule)) 
                                  _denyWriteData = true;
                            if (contains(FileSystemRights.WriteExtendedAttributes,rule)) 
                                  _denyWriteExtendedAttributes = true;
                        }else if (System.Security.AccessControl.AccessControlType.
                                  Allow.Equals(rule.AccessControlType)) {
                            if (contains(FileSystemRights.AppendData, rule))
                                  _allowAppendData = true;
                            if (contains(FileSystemRights.ChangePermissions, rule))
                                  _allowChangePermissions = true;
                            if (contains(FileSystemRights.CreateDirectories, rule))
                                  _allowCreateDirectories = true;
                            if (contains(FileSystemRights.CreateFiles, rule))
                                  _allowCreateFiles = true;
                            if (contains(FileSystemRights.Delete, rule))
                                  _allowDelete = true;
                            if (contains(FileSystemRights.DeleteSubdirectoriesAndFiles, 
                                  rule))_allowDeleteSubdirectoriesAndFiles = true;
                            if (contains(FileSystemRights.ExecuteFile, rule))
                                  _allowExecuteFile = true;
                            if (contains(FileSystemRights.FullControl, rule))
                                  _allowFullControl = true;
                            if (contains(FileSystemRights.ListDirectory, rule))
                                  _allowListDirectory = true;
                            if (contains(FileSystemRights.Modify, rule))
                                  _allowModify = true;
                            if (contains(FileSystemRights.Read, rule))_allowRead = true;
                            if (contains(FileSystemRights.ReadAndExecute, rule))
                                  _allowReadAndExecute = true;
                            if (contains(FileSystemRights.ReadAttributes, rule))
                                  _allowReadAttributes = true;
                            if (contains(FileSystemRights.ReadData, rule))
                                  _allowReadData = true;
                            if (contains(FileSystemRights.ReadExtendedAttributes, rule))
                                  _allowReadExtendedAttributes = true;
                            if (contains(FileSystemRights.ReadPermissions, rule))
                                  _allowReadPermissions = true;
                            if (contains(FileSystemRights.Synchronize, rule))
                                  _allowSynchronize = true;
                            if (contains(FileSystemRights.TakeOwnership, rule))
                                  _allowTakeOwnership = true;
                            if (contains(FileSystemRights.Traverse, rule))
                                  _allowTraverse = true;
                            if (contains(FileSystemRights.Write, rule))
                                  _allowWrite = true;
                            if (contains(FileSystemRights.WriteAttributes, rule))
                                  _allowWriteAttributes = true;
                            if (contains(FileSystemRights.WriteData, rule))
                                  _allowWriteData = true;
                            if (contains(FileSystemRights.WriteExtendedAttributes, rule))
                                  _allowWriteExtendedAttributes = true;
                        }
                    }
                }

                IdentityReferenceCollection groups = _principal.Groups;
                for (int j = 0; j < groups.Count; j++) {
                    for (int i = 0; i < acl.Count; i++) {
                        System.Security.AccessControl.FileSystemAccessRule rule = 
                            (System.Security.AccessControl.FileSystemAccessRule)acl[i];
                        if (groups[j].Equals(rule.IdentityReference)) {
                            if (System.Security.AccessControl.AccessControlType.
                                Deny.Equals(rule.AccessControlType)) {
                                if (contains(FileSystemRights.AppendData,rule)) 
                                    _denyAppendData = true;
                                if (contains(FileSystemRights.ChangePermissions,rule)) 
                                    _denyChangePermissions = true;
                                if (contains(FileSystemRights.CreateDirectories,rule)) 
                                    _denyCreateDirectories = true;
                                if (contains(FileSystemRights.CreateFiles,rule)) 
                                    _denyCreateFiles = true;
                                if (contains(FileSystemRights.Delete,rule)) 
                                    _denyDelete = true;
                                if (contains(FileSystemRights.
                                    DeleteSubdirectoriesAndFiles,rule)) 
                                    _denyDeleteSubdirectoriesAndFiles = true;
                                if (contains(FileSystemRights.ExecuteFile,rule)) 
                                    _denyExecuteFile = true;
                                if (contains(FileSystemRights.FullControl,rule)) 
                                    _denyFullControl = true;
                                if (contains(FileSystemRights.ListDirectory,rule)) 
                                    _denyListDirectory = true;
                                if (contains(FileSystemRights.Modify,rule)) 
                                    _denyModify = true;
                                if (contains(FileSystemRights.Read,rule)) 
                                    _denyRead = true;
                                if (contains(FileSystemRights.ReadAndExecute,rule)) 
                                    _denyReadAndExecute = true;
                                if (contains(FileSystemRights.ReadAttributes,rule)) 
                                    _denyReadAttributes = true;
                                if (contains(FileSystemRights.ReadData,rule)) 
                                    _denyReadData = true;
                                if (contains(FileSystemRights.
                                        ReadExtendedAttributes,rule)) 
                                    _denyReadExtendedAttributes = true;
                                if (contains(FileSystemRights.ReadPermissions,rule)) 
                                    _denyReadPermissions = true;
                                if (contains(FileSystemRights.Synchronize,rule)) 
                                    _denySynchronize = true;
                                if (contains(FileSystemRights.TakeOwnership,rule)) 
                                    _denyTakeOwnership = true;
                                if (contains(FileSystemRights.Traverse,rule)) 
                                    _denyTraverse = true;
                                if (contains(FileSystemRights.Write,rule)) 
                                    _denyWrite = true;
                                if (contains(FileSystemRights.WriteAttributes,rule)) 
                                    _denyWriteAttributes = true;
                                if (contains(FileSystemRights.WriteData,rule)) 
                                    _denyWriteData = true;
                                if (contains(FileSystemRights.
                                        WriteExtendedAttributes,rule)) 
                                    _denyWriteExtendedAttributes = true;
                            }else if (System.Security.AccessControl.AccessControlType.
                                    Allow.Equals(rule.AccessControlType)) {
                                if (contains(FileSystemRights.AppendData, rule))
                                    _allowAppendData = true;
                                if (contains(FileSystemRights.ChangePermissions, rule))
                                    _allowChangePermissions = true;
                                if (contains(FileSystemRights.CreateDirectories, rule))
                                    _allowCreateDirectories = true;
                                if (contains(FileSystemRights.CreateFiles, rule))
                                    _allowCreateFiles = true;
                                if (contains(FileSystemRights.Delete, rule))
                                    _allowDelete = true;
                                if (contains(FileSystemRights.
                                    DeleteSubdirectoriesAndFiles, rule))
                                    _allowDeleteSubdirectoriesAndFiles = true;
                                if (contains(FileSystemRights.ExecuteFile, rule))
                                    _allowExecuteFile = true;
                                if (contains(FileSystemRights.FullControl, rule))
                                    _allowFullControl = true;
                                if (contains(FileSystemRights.ListDirectory, rule))
                                    _allowListDirectory = true;
                                if (contains(FileSystemRights.Modify, rule))
                                    _allowModify = true;
                                if (contains(FileSystemRights.Read, rule))
                                    _allowRead = true;
                                if (contains(FileSystemRights.ReadAndExecute, rule))
                                    _allowReadAndExecute = true;
                                if (contains(FileSystemRights.ReadAttributes, rule))
                                    _allowReadAttributes = true;
                                if (contains(FileSystemRights.ReadData, rule))
                                    _allowReadData = true;
                                if (contains(FileSystemRights.
                                    ReadExtendedAttributes, rule))
                                    _allowReadExtendedAttributes = true;
                                if (contains(FileSystemRights.ReadPermissions, rule))
                                    _allowReadPermissions = true;
                                if (contains(FileSystemRights.Synchronize, rule))
                                    _allowSynchronize = true;
                                if (contains(FileSystemRights.TakeOwnership, rule))
                                    _allowTakeOwnership = true;
                                if (contains(FileSystemRights.Traverse, rule))
                                    _allowTraverse = true;
                                if (contains(FileSystemRights.Write, rule))
                                    _allowWrite = true;
                                if (contains(FileSystemRights.WriteAttributes, rule))
                                    _allowWriteAttributes = true;
                                if (contains(FileSystemRights.WriteData, rule))
                                    _allowWriteData = true;
                                if (contains(FileSystemRights.WriteExtendedAttributes, 
                                    rule))_allowWriteExtendedAttributes = true;
                            }
                        }
                    }
                }
            } catch (Exception e) {
                //Deal with IO exceptions if you want
                throw e;
            }
        }

        /// <span class="code-SummaryComment"><summary></span>
        /// Simply displays all allowed rights
        /// 
        /// Useful if say you want to test for write access and find
        /// it is false;
        /// <span class="code-SummaryComment"><xmp></span>
        /// UserFileAccessRights rights = new UserFileAccessRights(txtLogPath.Text);
        /// System.IO.FileInfo fi = new System.IO.FileInfo(txtLogPath.Text);
        /// if (rights.canWrite() && rights.canRead()) {
        ///     lblLogMsg.Text = "R/W access";
        /// } else {
        ///     if (rights.canWrite()) {
        ///        lblLogMsg.Text = "Only Write access";
        ///     } else if (rights.canRead()) {
        ///         lblLogMsg.Text = "Only Read access";
        ///     } else {
        ///         lblLogMsg.CssClass = "error";
        ///         lblLogMsg.Text = rights.ToString()
        ///     }
        /// }
        /// 
        /// <span class="code-SummaryComment"></xmp></span>
        /// 
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public override String ToString() {
            string str = "";
        
            if (canAppendData()) {if(!String.IsNullOrEmpty(str)) str+=
                ",";str+="AppendData";}
            if (canChangePermissions()) {if(!String.IsNullOrEmpty(str)) str+=
                ",";str+="ChangePermissions";}
            if (canCreateDirectories()) {if(!String.IsNullOrEmpty(str)) str+=
                ",";str+="CreateDirectories";}
            if (canCreateFiles()) {if(!String.IsNullOrEmpty(str)) str+=
                ",";str+="CreateFiles";}
            if (canDelete()) {if(!String.IsNullOrEmpty(str)) str+=
                ",";str+="Delete";}
            if (canDeleteSubdirectoriesAndFiles()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "DeleteSubdirectoriesAndFiles"; }
            if (canExecuteFile()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ExecuteFile"; }
            if (canFullControl()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "FullControl"; }
            if (canListDirectory()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ListDirectory"; }
            if (canModify()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "Modify"; }
            if (canRead()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "Read"; }
            if (canReadAndExecute()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ReadAndExecute"; }
            if (canReadAttributes()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ReadAttributes"; }
            if (canReadData()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ReadData"; }
            if (canReadExtendedAttributes()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ReadExtendedAttributes"; }
            if (canReadPermissions()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "ReadPermissions"; }
            if (canSynchronize()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "Synchronize"; }
            if (canTakeOwnership()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "TakeOwnership"; }
            if (canTraverse()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "Traverse"; }
            if (canWrite()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "Write"; }
            if (canWriteAttributes()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "WriteAttributes"; }
            if (canWriteData()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "WriteData"; }
            if (canWriteExtendedAttributes()) { if (!String.IsNullOrEmpty(str)) 
                str += ","; str += "WriteExtendedAttributes"; }
            if (String.IsNullOrEmpty(str))
                str = "None";
            return str;
        }

        /// <span class="code-SummaryComment"><summary></span>
        /// Convenience method to test if the right exists within the given rights
        /// <span class="code-SummaryComment"></summary></span>
        /// <span class="code-SummaryComment"><param name="right"></param></span>
        /// <span class="code-SummaryComment"><param name="rule"></param></span>
        /// <span class="code-SummaryComment"><returns></returns></span>
        public bool contains(System.Security.AccessControl.FileSystemRights right,
            System.Security.AccessControl.FileSystemAccessRule rule ) {
            return (((int)right & (int)rule.FileSystemRights) == (int)right);
        }    
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bruce Hatt
Founder Pur Investing Inc.
Canada Canada
No Biography provided

Comments and Discussions

 
QuestionGood work + simple question PinmemberTachyonx1-Dec-13 2:40 
QuestionGood effort, but has problems Pinmembermichel eissa18-Jul-13 7:43 
GeneralSimply great! PinmemberAlex1855-Jun-13 5:35 
GeneralMy vote of 5 PinmemberFjaconete8322-Feb-13 17:44 
GeneralMy vote of 1 [modified] PinmemberInba karthik17-Aug-12 1:22 
GeneralMy vote of 5 PinmemberReed.Cao9-Feb-12 19:29 
QuestionWorks Great Except For Root Folders Pinmemberaramka28-Dec-11 20:14 
AnswerRe: Works Great Except For Root Folders PinmemberBruce Hatt4-Jan-12 4:03 
GeneralRe: Works Great Except For Root Folders [modified] Pinmemberhtaddict26-Jun-12 19:22 
GeneralUnfortunalety... PinmemberTetranos19-Apr-10 23:09 
GeneralRe: Unfortunalety... PinmemberTadeusz Dracz24-Nov-10 5:56 
GeneralAlmost exactly what I need Pinmemberstaffan_v17-Feb-10 21:54 
GeneralThanks for the feedback! PinmemberBruce Hatt9-Oct-09 6:52 
Many years ago, I developed a web based client reporting app - a favour to our private client unit. Not having the time to spend on post-development tasks, I added a requirement for a web based installer and maintenance tool for non-technical administrative staff.
 
The app requires ongoing tasks like maintenance and an occasional install to a new server. Additional ongoing tasks are unwelcome to employees who are already overworked and not interested in learning a new app. To get buy-in it was important to save them time and make it easy. It its intuitive and saves time, it adds value to the firm and therefore the upfront effort is well worth it!
 
My inspiration for the installer came from tools like Drupal and Wordpress from the php world where there are lots of examples of how-to test "File Access Rights".
 
Determining the file access rights for files and directories was an essential part of the solution. I looked for a .NET solution with no luck so I researched it in .NEW and generated the code from this article.

I posted my code to save to time for anyone with a similar problem to mine- the code is not complicated but there was a few hours of research so writing itself would take time.
 
This is utility code and is not going to be part of any1 business logic. It is solves a minor problem but one you would not want to have to code yourself like a Base64 encoder or stream to string conversion. It's general enough that it can be useful for anyone accessing a file
 
Including this sort of functionality in the standard .NET distribution seems worthwhile and maybe they eventually will.
 
I appreciate the feedback and hope the code helps folks.../Bruce Hatt
 
1 Unless your building a file security app!
GeneralThanks for the effort ! Pinmemberciricivan9-Oct-09 0:01 
GeneralCode works perfectly Pinmemberahajou26-Mar-09 23:07 
GeneralThanks for the great feedback! PinmemberBruce Hatt27-Sep-07 9:00 
GeneralRe: Thanks for the great feedback! PinmemberCoolSpin6-Aug-09 23:50 
GeneralRevised and FxCop-ed version PinmemberDrag0nsAng3l27-Sep-07 0:55 
GeneralCode style PinmemberIgor Brejc7-Jul-07 22:28 
GeneralJust what I needed! PinmemberRFID Chris25-May-07 11:24 
GeneralRe: Just what I needed! PinmemberMaxSchmeling22-Dec-08 9:38 
GeneralCan't get it to work PinmemberJens Nordenbro2-Apr-07 2:09 
GeneralRe: Can't get it to work PinmemberJens Nordenbro2-Apr-07 2:43 
GeneralContains method Pinmemberatlaste1-Feb-07 23:51 
GeneralRemote machines Pinmemberbabushaikha25-Aug-06 11:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 13 Jul 2006
Article Copyright 2006 by Bruce Hatt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid