Get Special Folder

前端 未结 3 1171
清歌不尽
清歌不尽 2020-12-01 20:26

please just answer the question otherways do not respond to this question.

let me start again. How do I use this class, which extends the internal E

相关标签:
3条回答
  • 2020-12-01 20:48

    Edit: if you've inherited the code you've shown us and need to use it for some reason (instead of the built-in .NET method that appears to do the same thing), you should be able to use it like this:

    string path = EnvironmentFolders.GetPath(EnvironmentFolders.SpecialFolders.Fonts);
    

    Having said that, the Environment class has a public method that does nearly the same thing, GetFolderPath:

    string path = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
    

    The reflected code in .NET looks exactly like the code in your class, except it adds two things: it verifies that the parameter value is defined in the enumeration (since you can pass any integer to the method) and it demands that the caller has path discovery permission (a new FileIOPermission). Is it that last requirement you're trying to work around?

    Both methods are static, meaning you access them through the type that contains them, not an instance of that type:

     // Like this
     EnvironmentFolders.GetPath(...);
    
     // Not this
     EnvironmentFolders folders = new EnvironmentFolders();
     folders.GetPath(...);
    

    See the .NET documentation about Static Classes and Static Class Members for more information.

    0 讨论(0)
  • 2020-12-01 21:00
    string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
    
    0 讨论(0)
  • 2020-12-01 21:02

    Something like this added to the click event of your button.

    String path = EnvironmentFolders.GetPath(EnvironmentFolders.SpecialFolder.Favorites)
    //do something with the path.
    

    You need more info??

    ADDED ON EDIT: Comments are right the method is static this way should work (at least, it worked when I try it on a console app).

    0 讨论(0)
提交回复
热议问题