1

I tried to get access information of 'current user' folder. But this code always return "method failed with unexpected error code 3, InvailedOperationException".

Here is my code

string CurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var Info = new DirectoryInfo("C:\\users\\"+ CurrentUserName);
var Security = Info.GetAccessControl();
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
jaeseung you
  • 33
  • 1
  • 8
  • What is the value of `CurrentUserName`? On my machine, it's of the form `DOMAIN\username`, which gives a folder that doesn't exist.. – Blorgbeard Sep 29 '16 at 03:07
  • You're better off using `Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)`, anyway. – Blorgbeard Sep 29 '16 at 03:11
  • Thanks for the comment. I thought 'CurrentUserName' should get username only, not for Domain\username. – jaeseung you Sep 29 '16 at 03:59

1 Answers1

2

Thank you Blorgbeard. Here is the alternative code what you told. It works perfectly.

 string CurrentUserName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

 var Info = new DirectoryInfo(CurrentUserName);

 var Security = Info.GetAccessControl();
jaeseung you
  • 33
  • 1
  • 8