FileStream object: UnauthorizedAccessException with network UNC path

  • Thread starter Thread starter DC
  • Start date Start date
D

DC

Hi,

when I open / create a filestream like this:

FileStream(@"\\machinename\dir\file.dat",
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite
)

I receive UnauthorizedAccessException when "machinename" is not my
local machine, even thought everybody is allowed to do everything in
the share "\dir". I confirmed this by creating and using files in the
share on the machine the application is running on. The application is
a windows service just in case that matters.

I have read similar posts but they were all about asp.net or web
services and the problem was that these were running with different
credentials and therefore could not access the file.

Does anybody have a clue about what is causing this exception? TIA for
any comments.

Best regards

DC
 
The application is a windows service just in case that matters.

If not changed, then Windows services starts under the local system account
of the computer where they are running, which does not have access rights to
the shared directory.
Right click on the service, go properties and in the Log On tab select the
"This account" radio button and type in the credentials that has access to
the shared directory. Remember to stop and start it afterwards.
 
Hi Willy,

in case it still matters (maybe you know how to access the share
without changing the user the service is running on): the windows
service is on Windows 2000, the share is on a Windows 2003 box.

Best regards

DC
 
Back
Top