Re: File.Move
by coffeebasket@msn.com on 10/31/2007 5:55:00 PM
On 31 Okt, 15:43, John Duval <JohnMDu...@gmail.com> wrote:
> On Oct 31, 10:11 am, coffeebas...@msn.com wrote:
>
>
>
>
>
> > On 31 Okt, 12:57, John Duval <JohnMDu...@gmail.com> wrote:
>
> > > On Oct 31, 4:05 am, coffeebas...@msn.com wrote:
>
> > > > 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 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- D=F6lj citerad text -
>
> - Visa citerad text -
Hi John,
This is the code:
string mysource =3D
@"C:\Documents and Settings\tcncc\My Documents\Visual Studio
2005\Projects\MoveService\MoveService\bin\Debug
\2007-01-10_Designtidning_01.pdf";
string mytarget =3D
@"\\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
Re: File.Move
by John B on 11/2/2007 10:42:00 PM
coffeebasket@msn.com wrote:
> On 31 Okt, 15:43, John Duval <JohnMDu...@gmail.com> 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
Re: File.Move
by John Duval on 11/1/2007 8:53:00 PM
On Nov 1, 8:42 pm, John B <jbngs...@yahoo.com> wrote:
> coffeebas...@msn.com wrote:
> > On 31 Okt, 15:43, John Duval <JohnMDu...@gmail.com> 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
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