Access to Path is Denied.

T

Tim Peer

I am getting a dreaded Access To Path <file> is denied in a C# program. I
tried granting full access to ASPNET (local machine), the user running the
program (a domain administrator) and continue to get the error everytime I
attempt to access the file, create a new file or delete the file. I even
attempted to set fileIOPermission to what I believe to be all access for the
file and the directory with the same result.

Any advise would be greatly appreciated!

Tim
peertATenvysysDOTcomNothingElseFollowsThisEmailAddress.

System.IO.FileInfo finfo = new System.IO.FileInfo(ffile);


FileIOPermission fper = new
FileIOPermission(FileIOPermissionAccess.AllAccess,finfo.Directory.FullName);

//finfo.Attributes = FileAttributes.Normal;


if (!finfo.Exists) finfo.Create();


}

catch (Exception ec)

{

DevExpress.XtraEditors.XtraMessageBox.Show(this, ec.Message);

}
 
M

Mr. Arnold

Tim Peer said:
I am getting a dreaded Access To Path <file> is denied in a C# program. I
tried granting full access to ASPNET (local machine), the user running the
program (a domain administrator) and continue to get the error everytime I
attempt to access the file, create a new file or delete the file. I even
attempted to set fileIOPermission to what I believe to be all access for
the file and the directory with the same result.

Any advise would be greatly appreciated!

If this is on a Share, then you might want to check permissions on the
Share as opposed to permissions for a file or directory in the Share. User
account can have full permissions on the directory or file in a directory,
but permissions on the Share itself for the User account may not have those
rights, is not there or another account, like group account Everyone, as an
example, is superseding all rights on the Share.
 
A

Aneesh Pulukkul[MCSD.Net]

If this is on a Share, then you might want to check permissions on the
Share as opposed to permissions for a file or directory in the Share. User
account can have full permissions on the directory or file in a directory,
but permissions on the Share itself for the User account may not have those
rights, is not there or another account, like group account Everyone, as an
example, is superseding all rights on the Share.

Seems to be a problem with permission. Usually Access Denied will
occur due to two reasons 1)Insufficient permissions. 2)File is being
used because stream was not properly closed/disposed.
 
T

Tim Peer

Thank you Aneesh and Mr. Arnold,



I am attempting to create the file on a disk on the local system. The
username of the account running the C# program should have adequate privs
since it is in the administrators group. I have altered permissions on the
login (domain) user account, ASPNET local user account and no luck. It was
mentioned I might have an open stream on the file, I don't think this is the
case since I am creating a new file and SYSTEM.IO activity is limited to
this single method.



System.IO.FileInfo finfo = new System.IO.FileInfo(ffile);

if (!finfo.Exists) finfo.Create();



Do you know within which account the .NET 2.0 application executes. From
what I can see, my account being in the administrators group should not
raise this violation, but should the application execute from an account
proxy...



Also, I read that the USERS group is used by .NET application when such
errors occur but do not have a USERS group in Small Business Server 2003.



Thanks again for your help with this.



Tim
 
M

Mr. Arnold

Tim Peer said:
Thank you Aneesh and Mr. Arnold,



I am attempting to create the file on a disk on the local system. The
username of the account running the C# program should have adequate privs
since it is in the administrators group. I have altered permissions on the
login (domain) user account, ASPNET local user account and no luck. It was
mentioned I might have an open stream on the file, I don't think this is
the case since I am creating a new file and SYSTEM.IO activity is limited
to this single method.

I believe the machine/ASPNET account only comes into play for the ASP.NET
Worker Process and what permissions it has, such as permissions an ASP.NET
solution would have in a browser session to work with directory/files.
System.IO.FileInfo finfo = new System.IO.FileInfo(ffile);

if (!finfo.Exists) finfo.Create();



Do you know within which account the .NET 2.0 application executes. From
what I can see, my account being in the administrators group should not
raise this violation, but should the application execute from an account
proxy...



Also, I read that the USERS group is used by .NET application when such
errors occur but do not have a USERS group in Small Business Server 2003.



Thanks again for your help with this.

Maybe, the link will help you pin point what is happening.

http://www.codeproject.com/dotnet/UB_CAS_NET.asp
 
A

Aneesh Pulukkul[MCSD.Net]

I believe the machine/ASPNET account only comes into play for the ASP.NET
Worker Process and what permissions it has, such as permissions an ASP.NET
solution would have in a browser session to work with directory/files.












Maybe, the link will help you pin point what is happening.

http://www.codeproject.com/dotnet/UB_CAS_NET.asp- Hide quoted text -

- Show quoted text -

Just check the username for current thread using
System.Environment.UserDomainName + @"\" +
System.Environment.UserName, just before creating file.
And once you have the username then check the permissions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top