UnauthorizedAccessException
-
Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
// serialize some stuff
stream.Close();Why am I getting this error and does anyone know how to solve it?
-
Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
// serialize some stuff
stream.Close();Why am I getting this error and does anyone know how to solve it?
It most likely inherited rights from the parent folder, and got transfered somehow. Are you using Vista btw? I have seen the same thing happen there without explaination.**
xacc.ide-0.2.0 preview - Now in 100% C# goodness
**
-
It most likely inherited rights from the parent folder, and got transfered somehow. Are you using Vista btw? I have seen the same thing happen there without explaination.**
xacc.ide-0.2.0 preview - Now in 100% C# goodness
**
-
Hi, I'm buidling a forms application in which user settings can be stored and loaded from a file. So far so good. Now I'm trying to load a file of this type made by another user on another computer. It seems this causes some kind security problem: System.UnauthorizedAccessException: Access to the path 'C:\dotnet\myapp\bin\Debug\settings\defaults.set' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at 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) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.Open(String path, FileMode mode) The file in question is created simply as:
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
// serialize some stuff
stream.Close();Why am I getting this error and does anyone know how to solve it?
Is the file readOnly? Vasudevan Deepak Kumar Personal Homepage namespace LavanyaDeepak
Personal Weblog
The World of Deepak and Lavanya
Views and Reviews -
Is the file readOnly? Vasudevan Deepak Kumar Personal Homepage namespace LavanyaDeepak
Personal Weblog
The World of Deepak and Lavanya
Views and Reviews -
No, I'm not using Vista, but this would be a reasonable explanation: I think the user that created the file had the application installed into a folder on his desktop, which could mean the rights to his desktop stick to the file. Can anyone confirm this?
Definately a permission issue. If you run as Adminstrator you can take ownership and change the permissions, but else you out of luck. I doubt there will be any way to circumvent this security for a non admin user or the original creator of the file.**
xacc.ide-0.2.0 preview - Now in 100% C# goodness
**