Unable to create instance of class
TestClass. Error:
System.UnauthorizedAccessException:
Access to the path ‘C:\Documents and
Settings\Administrator\My
Documents\Visual Studio
2010\Projects\TestProject’ is denied.System.IO.__Error.WinIOError(Int32
errorCode, String maybeFullPath)
System.IO.FileStream.Init(String path,
FileMode mode, FileAccess access,
Int32 rights, Boolean useRights,
FileShare share, Int32 bufferSize,
FileOptions options,
SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy, Boolean
useLongPath)
System.IO.FileStream..ctor(String
path, FileMode mode, FileAccess
access, FileShare share, Int32
bufferSize, FileOptions options,
String msgPath, Boolean bFromProxy)
System.IO.FileStream..ctor(String
path, FileMode mode)
KM_Automation.KM_Library.GetAutoConfig() in C:\Documents and
Settings\Administrator\My
Documents\Visual Studio
2010\Projects\TestProject\Test_Library.cs:
line 40 KM_Automation.KM_Functional_Trans_General..ctor()
in C:\Documents and
Settings\Administrator\My
Documents\Visual Studio
2010\Projects\TestProject\TestClass.cs:
line 33
Test_Library.cs:
public string[] GetAutoConfig()
{
FileStream fs = new FileStream(sConfigFile, FileMode.Open); // line 40
StreamReader sr = new StreamReader(fs);
string line = "";
string[] arrline = new string[2];
}
TestClass.cs:
arrConfig = KMLib.GetAutoConfig(); // line 33
Why am I getting this error? I made sure that the folder is shared to everyone, and removed the Read Only.
You’re getting this error because as the exception message says the current user doesn’t have access to the file in question. You need to adjust the permissions of that file and it’s parent directories to allow access to the user in question
Part of the problem is your choice of location. It looks like you are attempting to share a configuration file between a set of users yet you’ve chosen the location of the document to be under the Administrator directory.
If you want to share amongst users then I would use the
All UsersorPublicdirectory instead as it’s meant for this type of operation.