By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

File access question

P: n/a
Hello folks,

I am experiencing a rather strange problem. I have written a service
that attempts to open a file on a network share via a FileStream object.
When I try to open the file from my service, I get the "Access is
denied" error. However, if I try to open the file from a GUI
application, I can open the file without problem. I've tried using the
FileIOPermissions object to get around the error with no luck. Obviously
I am missing something very fundamental, the file is accessible to
'Everyone'. Does anybody know what I am doing wrong? Thank you,

Jason

Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Jason

Maybe it's rather a Windows than a .NET issue. The service may not have
enough privilegies to access the folder while your UI application (which
runs under the context of your user account) does...

Regards

Philipp

Hello folks,

I am experiencing a rather strange problem. I have written a service
that attempts to open a file on a network share via a FileStream object.
When I try to open the file from my service, I get the "Access is
denied" error. However, if I try to open the file from a GUI
application, I can open the file without problem. I've tried using the
FileIOPermissions object to get around the error with no luck. Obviously
I am missing something very fundamental, the file is accessible to
'Everyone'. Does anybody know what I am doing wrong? Thank you,

Jason

Nov 16 '05 #2

P: n/a
You are probably running into CAS issues. Fileshare is considered
LocalIntranet_Zone even if it is shared from your local computer. You
probably need to go to the .Net configuration tool and give that share a
special permissions. The tool is under aministrative tools, .Net
Framewwork 1.1 Configuration. Go to runtime security policy, Machine,
All_code and Add a child code group. Give it a name then on the choose a
condition tab select URL. In the bottom text field put the path to the
file share. I.E. file://F:/*. On the next tab select the permission set.
Leave it at FullTrust if you want all permissions. Now you should get no
errors accessing the file share.

Good Luck
Leon Lambert

Jason Hurder wrote:
Hello folks,

I am experiencing a rather strange problem. I have written a service
that attempts to open a file on a network share via a FileStream object.
When I try to open the file from my service, I get the "Access is
denied" error. However, if I try to open the file from a GUI
application, I can open the file without problem. I've tried using the
FileIOPermissions object to get around the error with no luck. Obviously
I am missing something very fundamental, the file is accessible to
'Everyone'. Does anybody know what I am doing wrong? Thank you,

Jason

Nov 16 '05 #3

P: n/a
"Access denied" errors are due to Windows permissions denials, not CAS
permission denials, so altering the CAS policy will not resolve this
problem.
"Leon Lambert" <la******@inil.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
You are probably running into CAS issues. Fileshare is considered
LocalIntranet_Zone even if it is shared from your local computer. You
probably need to go to the .Net configuration tool and give that share a
special permissions. The tool is under aministrative tools, .Net
Framewwork 1.1 Configuration. Go to runtime security policy, Machine,
All_code and Add a child code group. Give it a name then on the choose a
condition tab select URL. In the bottom text field put the path to the
file share. I.E. file://F:/*. On the next tab select the permission set.
Leave it at FullTrust if you want all permissions. Now you should get no
errors accessing the file share.

Good Luck
Leon Lambert

Jason Hurder wrote:
Hello folks,

I am experiencing a rather strange problem. I have written a service that
attempts to open a file on a network share via a FileStream object. When
I try to open the file from my service, I get the "Access is denied"
error. However, if I try to open the file from a GUI application, I can
open the file without problem. I've tried using the FileIOPermissions
object to get around the error with no luck. Obviously I am missing
something very fundamental, the file is accessible to 'Everyone'. Does
anybody know what I am doing wrong? Thank you,

Jason

Nov 16 '05 #4

P: n/a
Manipulating FileIOPermissions will not help resolve this exception since
"access denied" errors are caused by Windows permissions restrictions and
have nothing to do with .NET code access security.

A couple of questions:

1. If you launch the service using the same user credentials with which you
can open the file via the GUI application, can the service open the file?

2. Are you sure that "everyone" access is truly applied, or does this
reflect just the permissions on the share, as opposed to the Windows ACL on
the actual file? Access to a file via a share will be determined by the
intersection, not the union, of the permissions on the share and the file
itself.
"Jason Hurder" <jhurder@spam_me_not.fastpicsystems.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
Hello folks,

I am experiencing a rather strange problem. I have written a service that
attempts to open a file on a network share via a FileStream object. When I
try to open the file from my service, I get the "Access is denied" error.
However, if I try to open the file from a GUI application, I can open the
file without problem. I've tried using the FileIOPermissions object to get
around the error with no luck. Obviously I am missing something very
fundamental, the file is accessible to 'Everyone'. Does anybody know what
I am doing wrong? Thank you,

Jason

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.