I wish to get the size of folder
C:\ProgramData\
I use the following code
public static long GetDirectorySize(string folderPath)
{
DirectoryInfo di = new DirectoryInfo(folderPath);
return di.EnumerateFiles("*", SearchOption.AllDirectories).Sum(fi => fi.Length);
}
But it prompts me error:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path 'C:\ProgramData\Application Data' is denied.
I have already set the
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
in app.manifest. It seems that even I open C:\ProgramData\Application Data in windows directly it is denied.
How to resolve this problem?