C# FileInfo.MoveTo

J

jman

I have an urgent question.

I have written a .Net C# windows services that has only
one key purpose: to move files from the machine that is
running the service to a network download server for
company distribution of data. When I try to call the
FileInfo.MoveTo() method, I receive the following error:

System.UnauthorizedAccessException: Access to the path is
denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String
str)
at System.IO.__Error.WinIOError()
at System.IO.FileInfo.MoveTo(String destFileName)
at FileDownloadService.Service1.timer1_Elapsed_1(Object
sender, ElapsedEventArgs e) in c:\uhaul .net
solutions\filedownload\filedownloadservice\service1.cs:line
194

I have mapped a drive to our network server and am trying
to move the files to it and am getting an Access error.

Is there a way to specify user credentials for the server
that you are trying to move files to? In other words, can
I move files to a network server by using the server's
friendly name (UNC) and provide user name/password for
authentication purposes? Any help would be greatly
appreciated!!

Thanks,
jman
 
M

Miha Markic

Hi,

I wonder why don't you run the service under some account that has enough
privileges to access the server?
 
J

jman

Thanks for the reply!! I have had trouble getting that to
work. I can, for example, create a regular windows
application that calls the FileInfo.MoveTo() method using
the UNC of the remote server and get the file to move
without a problem; it's when I try to do the exact same
thing from a windows service that I get the access denied
error.

How would I go about getting the service's FileInfo.MoveTo
() to use a particular user account on a remote machine?
It appears that I need to specify authentication info...
Any insight is greatly appreciated.

Thanks,
jman
 
M

Miha Markic

Hi jman,

jman said:
Thanks for the reply!! I have had trouble getting that to
work. I can, for example, create a regular windows
application that calls the FileInfo.MoveTo() method using
the UNC of the remote server and get the file to move
without a problem; it's when I try to do the exact same
thing from a windows service that I get the access denied
error.

How would I go about getting the service's FileInfo.MoveTo
() to use a particular user account on a remote machine?
It appears that I need to specify authentication info...
Any insight is greatly appreciated.

No, your problem is that when running windows forms app it is using current
logged account (that's you) while the service account should be set manually
(the account under which the service is running).
Go to administrative tools/services, find your service, right
click/properties and check out Log On tab.
 
J

jman

I appreciate all your help!! I think you've pointed me in
the right direction!! Thanks again!!

jman
 

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