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
To get access to the
MyDocuments
folder.You can set the program so you can only run as administrator.
In Visual Studio:
Right click on the Project -> Properties -> Security -> Enable ClickOnce Security
After you clicked it, a file will be created under the Project's properties folder called app.manifest once this is created, you can uncheck the Enable ClickOnce Security Settings option
Open that file and change this line :
to:
This will make the program require administrator privileges, and it will guarantee you have access to that folder.
From
Environment.SpecialFolder
Just use
In my computer, it returns as
C:\Users\Soner\Documents
Since
SpecialFolder
is enum type, you can iterate their values in a loop. Here how it looks like;