1

I have read this post. I am trying to move a file from one place to another on a Windows server. The user running the F# program has full privileges to execute the .Net File.Move statement and I tested this move manually using the same user logged into the server using File Explorer.

I am trying to figure out what I am doing wrong.

Here is relevant code, and copyOnly is false.

let rc =
    try
       if copyOnly then
          File.Copy((currentPath + fnam), (destPath + new_file_dest)) |> ignore
          logH.WriteLine(generateTimeStamp () + ": " + currentPath + fnam + " copied to " + (new_file_dest + fnam))
       else
          File.Move((currentPath + fnam), (destPath + new_file_dest)) |> ignore
          logH.WriteLine(generateTimeStamp () + ": " + currentPath + fnam + " moved to " + destPath + new_file_dest)
                true 
    with ex -> 
       logH.WriteLine(generateTimeStamp () + ": " + "An error occrred trying to move or copy " + currentPath + fnam + " to " + (destPath + new_file_dest))
       printfn "%A" ex
       false
rc

currentPath = \\\\Munis2\\musys_read\\musys\\import_prod\\
fnam = import_arlckbox.007
destPath = \\\\Munis2\\Munis_IC_DataExchange\\archive\\
new_file_dest = import_arlckbox_6132018_15645.007

I am stumped as to why this is a problem. Looking at the other article (post), I did make sure both users I am testing with have full privileges in all the directories, and I am moving one file to another file name in another directory. That was one of the resolutions in the referenced article.

I have a second question related to the error. If I was trying to debug this problem using URL path syntax, as indicated above, which user is trying to perform this task on the server?

Is the user the same user as on the workstation debugging in Visual Studio, or is the request to move or copy handled by a default internet user?

I am asking this, because after fixing the corrupt path problem, I was still getting the access to the path is denied error debugging using URLs, but not when the application was running directly on the server.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
  • 2
    Could you please explain exactly how the values for `currentPath` and `destPath` are obtained or declared in the program? I'm wondering if it's not related to the double backslash in someway (or lack there of in `musys_read\musys`)... –  Jun 13 '18 at 20:01
  • @ThomasCorbière I found the problem. It's a bad path. – octopusgrabbus Jun 14 '18 at 11:33

2 Answers2

1

I don't know F# but in Windows app or Windows Server you need to use Application ExecutablePath and Remove bin\Debug as shown

 string startupPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) + "\\Templates");

 startupPath = startupPath.Replace("bin\\Debug\\", string.Empty);

 var newfileName2 = Guid.NewGuid() + ".xlsx";

 string destinationPath = Path.Combine(startupPath, newfileName2);

 File.Copy(sourcefile, destinationPath, true);

This is C# code. Posted this code to get some idea for your Question

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131
  • This program is being executed out of Visual Studio 2012 using URL paths, and this is for debugging purposes. The production application uses drive letters and paths, and gets the same error. So, I am confused about your answer. – octopusgrabbus Jun 14 '18 at 11:30
1

First, there was a path problem. The partial path (without the file name) was being copied into the full path with the file name. Once the application's Access database (source of the paths used by the program) was set back to using standard Windows drive paths -- G:\dir1\dir2\file1.007 and the invalid path was fixed, the program went back to normal.

It would still be nice if File.Move (or Copy) would provide a more robust error.

octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131