Reputation: 8986
I am trying to create a FileStream but keep getting "UnauthorisedAccessException", what is wrong with this statement?
FileStream fs = new FileStream(@"C:\", FileMode.Create, FileAccess.ReadWrite);
Thanks,
Eamonn
Upvotes: 0
Views: 1025
Reputation: 41
I think the path should be a filename - "c:\test.txt" rather than the location.
Also watch that c:\ is available, depending on the OS it can be protected (eg in Vista/Win 7)
Upvotes: 3
Reputation: 174457
You are not allowed to open a file stream that points to the root directory of your C partition. I assume, that's not what you want to do. If you want to create a file, than specify a file name.
Upvotes: 3