I'm using C# .NET 4 with VS 2010.
When Iterating over some paths, I'm running this line:
files = Directory.GetFiles(path, searchPattern);
I get an exception when the path is the documents and settings folder. How can I access it? And no, I don't want to skip the folder with a try and catch. I want to be able to access it somehow.
Edit: I got a follow up question. As I told you, I'm iterating over the paths. Is there a way to use Environment.GetFolderPath
but somehow idetifying the correct speical folder according to the path I'm currently checking?
You have to use like this
var mydocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
To get access to the MyDocuments
folder.
I edited my question to add a follow up question if you may know the answer to that as well.
you can very well equate the path that you have with this
Environment.GetFolderPath(...)
and if matched, you can continue or else you can just callContinue
in the looping construct.I meant something automatically. something like (pseudo code): SpeicalFolder folder = Environment.GetSpeicalFolderByFullPath(path);
No.. Environment.GetFolderPath takes only the enumeration as a path. Not a string.
I would like to suggest you the following. During the application start, you can just cache the full path of all of the special folders and then check them during runtime. Let me know if that would be fine for your requirement.