Raskolnikov
Raskolnikov

Reputation: 3999

How to rename folder in network shared folder?

I need to rename folder on network (I am using VPN). Since this is on network I have to connect using credentials. I have all permissions to read and write in shared folder. Same logic with connection to network is working when I want to delete, edit or save in same folder.

Same function is working for rename files.

Problem is just when I want to rename Folder !

This is function:

   public async Task<bool> Rename(string oldPath, string newPath )
    {
        using (var network = new NetworkConnection(configuration.Value.Host, networkCredential))
        {
            network.Connect();
            File.Move(oldPath, newPath);
            return await Task.FromResult(true);
        }
    }

For example this are function parameters:

oldPath => \\10.174.133.199\SharedFolder\MyFolder

newPath => \\10.174.133.199\SharedFolder\RenamedFolder

Upvotes: 0

Views: 1081

Answers (1)

Alfie Goodacre
Alfie Goodacre

Reputation: 2793

The issue you are facing is that you are using File.Move - a folder is not a File, but instead a Directory, as such you should use Directory.Move instead

Directory.Move(oldPath, newPath);

Upvotes: 3

Related Questions