Link to home
Start Free TrialLog in
Avatar of CynergySoftware
CynergySoftwareFlag for United States of America

asked on

access denied on copying files?

ok i am trying to copy a file here from  a local source to a remote source
I have verifed i have permission and from the local source i can manually copy files into the directory on the remote source

here is the code
try
                  {
                        int debug = (int) clsLogManager.clsLogger.LoggingLevel.DEBUG;
                        log.WriteToLog(debug, "Attempting to copy local file to remote server");
                        FileInfo local = new FileInfo(localPath+fileName);
                        log.WriteToLog(debug, "Local Path:"+localPath+fileName);
                        FileInfo mapped = new FileInfo(sharedPath+fileName);
                        log.WriteToLog(debug, "Remote Path:"+sharedPath+fileName);
                        if(local.Exists)
                        {
                              log.WriteToLog(debug, "Local File Exists");
                              local.CopyTo(sharedPath+fileName,true);                                                      
                              log.WriteToLog(debug, "Copy successful");
                        }            
                        else
                        {
                              log.WriteToLog(debug, "Local file does not exist");
                        }
                  }
                  catch(Exception ex)
                  {                  
                        log.WriteToLog((int) clsLogManager.clsLogger.LoggingLevel.EXCEPTION, ex.Message);
                  }


Now here is the log data with the error message

 Attempting to copy local file to remote server
DEBUG: -- 5/27/2006 3:24:43 PM -- Local Path:C:\NetShare\Dialer\VoiceFiles\1345216470.wav
DEBUG: -- 5/27/2006 3:24:43 PM -- Remote Path:\\<server name>\Dialer\VoiceFiles\1345216470.wav
DEBUG: -- 5/27/2006 3:24:43 PM -- Local File Exists
EXCEPTION -- 5/27/2006 3:24:43 PM -- Access to the path "\\<server name>\Dialer\VoiceFiles\1345216470.wav" is denied.

like I said i can do this fine by browsing to the remote directory and copying files to it.

any ideas?



I have masked the ip address for obvisous reasons =)
Avatar of anyoneis
anyoneis
Flag of United States of America image

What is in sharedPath? Exactly?

Can you perform the copy by going to a cmd prompt and doing a copy?

Grasping at straws here :-)

David

Avatar of CynergySoftware

ASKER

yes from the command prompt i can manually type the copy

copy C:\NetShare\Dialer\VoiceFiles\1345216470.wav  \\<Server Name>\Dialer\VoiceFiles\1345216470.wav

and it copies just fine
This is a Winforms app, right? The program is running using your credentials?

Is your app running as a normal application (or some other type i.e. windows service, asp.net, webservice, etc) where it might be running as another user?
yes it is a windows application
and it is running as the same user that i went through command prompt with
OK, you're really gonna think I'm nuts, but does the file already exist? You could add the second parameter to the CopyTo call...

Arghh... Pulease ignore that last burst of static... <sigh>
ASKER CERTIFIED SOLUTION
Avatar of anyoneis
anyoneis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok it seem the file was in use... so instead of trying to copy it right after it gets created. I am threading out a FileSystemWatch object. and that monitors the folder and copies new and updated files to the remote server as needed. It checks to see if in use. If it is then it sleeps a few seconds and tried again.

anyoneis you reply helped me get to this so awarding points to you....thanks
Thanks for the points! And more importantly, thanks for filling the rest of us in on what you found! I used exactly the same technique in a DirectorySweep program I wrote.

David