Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,
I have create one Windows service which create one file and i want to move this file to another PC.
In Destination PC i have create one folder and share it and also apply full right.
When i copy file from Command prompt it's working file. But in my .net code it's give me error for Access denid. Both PC contain Windows Server 2008 OS.
i have write code like
System.IO.File.Copy(strSourcepath,strDestPath,true);


Please help me why this give error.
Posted
Comments
Sergey Alexandrovich Kryukov 24-Jun-14 1:53am    
So, what's so wonderful? If access denied, it is denied. First of all, use legitimate file locations, never hard-coded. Or run your application under elevated privileges...
I don't know why your question needs an answer — you already answered it by yourself...
—SA
Savalia Manoj M 24-Jun-14 1:57am    
thanks for reply..I had use sourcepath="C:\GeneratedFile\Test.txt" and DestinationPath="\\WebServer\GeneratedFile\Test.txt".
What's Wrong??
Vi(ky 24-Jun-14 1:57am    
try with Full Qualified Name like "C:\Users\Jack\Documents\TEMP\directoryB\file.txt" for both source & destination path.

1 solution

Probably, it's a permissions problem.

When you do a file copy from the command line, you are running it as the logged in user: so the destination folder is accessed using the user permissions.
When your service runs, it does not run as a "normal" user - because no user has been logged in when the services are started - so it acquires different permissions.
You either need to assign the service to a particular account, or give appropriate access permissions to your destination folder.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900