Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 373611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:19:30+00:00 2026-05-12T14:19:30+00:00

I have read over the documentation, scoured the interwebs, and it seems what I

  • 0

I have read over the documentation, scoured the interwebs, and it seems what I want to do cannot be done without writing a custom CAS permission. So, here’s my last ditch attempt.

I want to DECLARATIVELY define a FileIOPermission (Attribute) on my class to demand permission to the users MyDocuments directory.
This directory is not consistent on all operating systems, and is generally accessed in .net through Path.GetFolderPath (I think thats it), passing a SpecialFolder enum value.
Is there any ‘token’ syntax, or similar feature in the FileIOPermissionAttribute to say to the runtime – ‘give me access to this SpecialFolder, wherever it may be on this system’?

If not I guess I’ll have to write a custom Permission object which does essentially that…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:19:30+00:00Added an answer on May 12, 2026 at 2:19 pm

    You don’t actually need a custom permission for this, but you do need a custom attribute that resembles FileIOPermissionAttribute. In its CreatePermission method, you can create a FileIOPermission for the actual folder path corresponding to SpecialFolder value passed to the attribute. e.g. (that needs some validation added):

    [Serializable]
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
    public sealed class SpecialFolderIOPermissionAttribute : CodeAccessSecurityAttribute
    {
        private Environment.SpecialFolder _folder;
        private FileIOPermissionAccess _access;
    
        public SpecialFolderIOPermissionAttribute(SecurityAction action)
            : base(action)
        {
            this.Unrestricted = true;
        }
    
        public Environment.SpecialFolder Folder
        {
            get
            {
                return this._folder;
            }
            set
            {
                this._folder = value;
                this.Unrestricted = false;
            }
        }
    
        public FileIOPermissionAccess Access
        {
            get
            {
                return this._access;
            }
            set
            {
                this._access = value;
                this.Unrestricted = false;
            }
        }
    
        public override IPermission CreatePermission()
        {
            FileIOPermission permission;
            if (this.Unrestricted)
            {
                permission = new FileIOPermission(PermissionState.Unrestricted);
            }
            else
            {
                permission = new FileIOPermission(this.Access, Environment.GetFolderPath(this.Folder));
            }
    
            return permission;
        }
    }
    

    One thing to watch out for here is that Environment.GetFolderPath will make a demand for PathDiscovery access on the target folder, so you’ll have to decide if you want to assert that permission in your CreatePermission method. (Personally, I suspect that the complications around this may be one of the reasons that the BCL team didn’t implement special folder support in FileIOPermissionAttribute in the first place.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have quickly read over the Microsoft Lambda Expression documentation. This kind of example
I have read over this which sort of gives an explanation of when you'd
I have read over a dozen posts and answers ... to no avail. What
Alright...I've given the site a fair search and have read over many posts about
I'm new to MVC, but I've been all over this, read all the documentation
From what I have read, using Speek over Nellymoser is advantageous , but I
I have read through all PHP documentation on IMAP functions (www.php.net/imap), but didn't find
I've read through the custom tags and filters documentation , but I'm not seeing
I have read through several reviews on Amazon and some books seem outdated. I
I have read a lot that LISP can redefine syntax on the fly, presumably

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.