none
.NET Directory.Move() fails for One Drive folders RRS feed

  • Question

  • For the call:

    // Directory.Exists(path) returns true
    // path = "C:\\Users\\david\\OneDrive - Windward Studios\\Documents\\AutoTag\\templates"
    Directory.CreateDirectory(backupFolder);
    Directory.Move(path, Path.Combine(backupFolder, Path.GetFileName(path)));

    Throws the exception:

    System.IO.IOException
      HResult=0x80070005
      Message=Access to the path 'C:\Users\david\OneDrive - Windward Studios\Documents\AutoTag\templates' is denied.
      Source=mscorlib
      StackTrace:
       at System.IO.Directory.InternalMove(String sourceDirName, String destDirName, Boolean checkHost)
       at System.IO.Directory.Move(String sourceDirName, String destDirName)
       at AutoTagCore.net.windward.autotag.controls.options.CopyTemplates.UpdateFiles() in C:\git\Jenova\autotag\AutoTagCore\net\windward\autotag\controls\options\CopyTemplates.cs:line 480
    
      This exception was originally thrown at this call stack:
        System.IO.Directory.InternalMove(string, string, bool)
        System.IO.Directory.Move(string, string)
        AutoTagCore.net.windward.autotag.controls.options.CopyTemplates.UpdateFiles() in CopyTemplates.cs

    Why doesn't this work? And what can I do to fix it?


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Wednesday, March 4, 2020 10:04 PM

Answers

  • For the call:

    // Directory.Exists(path) returns true
    // path = "C:\\Users\\david\\OneDrive - Windward Studios\\Documents\\AutoTag\\templates"
    Directory.CreateDirectory(backupFolder);
    Directory.Move(path, Path.Combine(backupFolder, Path.GetFileName(path)));
    Why doesn't this work? And what can I do to fix it?

    Your backupFolder var probably doesn't end with a \

    You should really show more code.  What you've done here is show up at the doctor's office with a sucking chest wound and coquettishly revealed a little bit of shoulder.

    Thursday, March 5, 2020 1:34 PM

All replies

  • Hi DavidThi808,

    Thank you for posting here.

    According to your description, I make a test on my side and get the same exception when I open the file in another application.

    You need to make sure that no file in the directory is in use and you have full control permission to the folder.

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 5, 2020 7:06 AM
    Moderator
  • Hi Xingyu;

    I don't think that's it - there's no file open. Also the error message is "Access to the path is denied." and that strikes me as a directory permission.

    What we're doing at this point is moving files in a folder under the user's documents and it works fine as long as it's not in One Drive. Is there something special about One Drive permissions?

    Or do we need to identify the path to it differently?

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Thursday, March 5, 2020 12:44 PM
  • For the call:

    // Directory.Exists(path) returns true
    // path = "C:\\Users\\david\\OneDrive - Windward Studios\\Documents\\AutoTag\\templates"
    Directory.CreateDirectory(backupFolder);
    Directory.Move(path, Path.Combine(backupFolder, Path.GetFileName(path)));
    Why doesn't this work? And what can I do to fix it?

    Your backupFolder var probably doesn't end with a \

    You should really show more code.  What you've done here is show up at the doctor's office with a sucking chest wound and coquettishly revealed a little bit of shoulder.

    Thursday, March 5, 2020 1:34 PM
  • Hey, DavidThi808.  Thanks for the answer credit, but which of the 2 suggestions worked for you?  I'd like to remove the one that isn't relevant. 

    I'm guessing that the backupFolder var needed a \ terminator, because looking at your code again it looks like you're actually moving subfolders into backupFolder, in which case you would want to create that directory first?

    Thursday, March 5, 2020 5:10 PM
  • Sorry yes - it's the trailing \ that was needed.

    Interesting that outside of One Drive that wasn't a problem. But it's a legit thing to require.


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Thursday, March 5, 2020 5:15 PM
  • I don't believe it's related.  It looks like you're copying from a local filesystem directory that just happens to have One Drive in its name to backupFolder which I would assume is the actual One Drive or remote storage directory.

    If you showed what the real string value of backupFolder is then it's probably explainable by the fact that it's a URI format instead of a filesystem path format and you're trying to conjoin that URI using Path.Combine which is intended for use with strings formatted as filesystem paths.  That's just a wild guess.


    Thursday, March 5, 2020 5:44 PM