File.Move

  • Thread starter Thread starter coffeebasket
  • Start date Start date
C

coffeebasket

I have created an Windows Service application, and it is suppose to
move downloaded files from localdir to a network dir but it fails. The
same code in a consol application works just fine. I have tried
username + password
in the Windows Service application but still no luck. Could someone
shead some light ?

tcncc
 
I have created an Windows Service application, and it is suppose to
move downloaded files from localdir to a network dir but it fails. The
same code in a consol application works just fine. I have tried
username + password
in the Windows Service application but still no luck. Could someone
shead some light ?

tcncc

Hi tcncc,
Are you trying to copy to a mapped network drive instead of using a
UNC path (Z:\MyDir versus \\server\share\MyDir)? A service won't have
access to mapped drives, even if you are supplying the same
credentials as those used in your console application. If you are
doing this, just switch to using UNC.
John
 
Hi tcncc,
Are you trying to copy to a mapped network drive instead of using a
UNC path (Z:\MyDir versus \\server\share\MyDir)? A service won't have
access to mapped drives, even if you are supplying the same
credentials as those used in your console application. If you are
doing this, just switch to using UNC.
John

Hi John

Yes I am using a UNC path, this is the acual path (\\Tcn4fs1\Gemdata
\CC). Really anoying because I need this to work.
// Christoffer
 
Hi John

Yes I am using a UNC path, this is the acual path (\\Tcn4fs1\Gemdata
\CC). Really anoying because I need this to work.
// Christoffer- Hide quoted text -

- Show quoted text -

Hi Christoffer,
What error are you getting?
For what it's worth, I created a standard .NET service, added an
installer component, added File.Move in the OnStart method and made
the target directory a UNC path, like so:

File.Move(@"c:\temp\foo.txt", @"\\myserver\share\subdir\foo.txt");

When I installed the service, I entered my domain user/password. When
I start the service, the file is moved just fine. Perhaps you could
do the same exercise, or at least post the error you're getting?
John
 
Hi Christoffer,
What error are you getting?
For what it's worth, I created a standard .NET service, added an
installer component, added File.Move in the OnStart method and made
the target directory a UNC path, like so:

File.Move(@"c:\temp\foo.txt", @"\\myserver\share\subdir\foo.txt");

When I installed the service, I entered my domain user/password. When
I start the service, the file is moved just fine. Perhaps you could
do the same exercise, or at least post the error you're getting?
John- Dölj citerad text -

- Visa citerad text -

Hi John,

This is the code:

string mysource =
@"C:\Documents and Settings\tcncc\My Documents\Visual Studio
2005\Projects\MoveService\MoveService\bin\Debug
\2007-01-10_Designtidning_01.pdf";
string mytarget =
@"\\Tcn4fs1\Gemdata\CC\2007-01-10_Designtidning_01.pdf";
File.Move(mysource, mytarget);


And this is the error:

System.UnauthorizedAccessException: Access to the path is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Move(String sourceFileName, String destFileName)
at MoveService.Service1.OnElapsedTime(Object source,
ElapsedEventArgs e) in C:\Documents and Settings\tcncc\My Documents
\Visual Studio 2005\Projects\MoveService\MoveService\Service1.cs:line
51

And the permissions to the network drive is:

Full Control Yes
Modify Yes
Read & Execute Yes
List Folders Contents Yes
Read Yes
Write Yes
Special Permissions No


The permission is the same as on my local drive, and move from c:\here
to c:\there works ok.

// Christoffer
 
On 31 Okt, 15:43, John Duval <[email protected]> wrote:
string mysource =
@"C:\Documents and Settings\tcncc\My Documents\Visual Studio
2005\Projects\MoveService\MoveService\bin\Debug
\2007-01-10_Designtidning_01.pdf";
string mytarget =
@"\\Tcn4fs1\Gemdata\CC\2007-01-10_Designtidning_01.pdf";
File.Move(mysource, mytarget);


And this is the error:

System.UnauthorizedAccessException: Access to the path is denied.
<...>
The user your service is running as(LOCAL SYSTEM) probably doesnt have
access to your docs & settings path or the share path.
Try running your service as your credentials and see if it works.

JB
 
<...>
The user your service is running as(LOCAL SYSTEM) probably doesnt have
access to your docs & settings path or the share path.
Try running your service as your credentials and see if it works.

JB

Hi JB,
That definitely would be a problem, but Christoffer said "I have tried
username + password in the Windows Service application but still no
luck". Worth double-checking though, maybe he put it back to
LOCAL_SYSTEM.

Christoffer, have you had a chance to try creating a new service
project with just the File.Move( ) in the OnStart method? I was also
wondering if it's possible that the permissions problem is because the
source file is in use (as opposed to permissions on the destination).
It sounds like your program waits for files to be dropped into a local
directory and moves them to a network drive... perhaps it's trying to
move them while they are still being dropped into the local
directory? I tend to doubt this is the problem -- but it's worth
checking.

John
 

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

Back
Top