I am attempting to write a process that will move a file from a directory on a server, to a network share, that will not be on that computer. The methodology worked just fine when moving from my local machine to the network share. However, it is not working when I put the process on my server (this process is basically a dll, that gets picked up by a running service, the service spins up a thread, gives it to my process, and away it goes). The process is running using an identity that has access to the shared directory, but it just won't move it. I can't detect an exception occuring either. I have pretty good logging in there and no exceptions seem to be thrown. I will look closer, but has anyone tried to do anything like this before? I call either this...
File.Move(@"C:\Output\" + FileTitle, ShareDirectory + "\\" + FileTitle);
Or this...
File.Copy(@"C:\Output\" + FileTitle, ShareDirectory + "\\" + FileTitle, true);
depending on whether or not the file exists or not... I am not certain impersonating anything would solve anything? The service already runs under an ldap username that has access to the share...
UPDATE: More information discovered
Ok, I had an incorrect condition that was never hit, so that is why I wasn't catching an exception... I get this exception...
Exception Publishing Document to Share: System.UnauthorizedAccessException: Access to the path is denied.
Once I saw that exception I decided to impersonate a valid user... And I am still getting that exception... Would mapping that directory on the server help at all? I am guessing no, but I am running out of ideas.
UPDATE: when I impersonate myself vs other users
When I impersonate my self in the process I am able to successfully move the file to the share. But If I impersonate another username that should have the same rights, I still get the above exception. I am not certain why this is occurring. Maybe this user doesn't have the permissions that I suspect it has. But just looking in windows and looking at the LDAP server it appears as though it does. Very curious indeed.