Raskolnikov Raskolnikov - 1 year ago 162
C# Question

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))
File.Move(oldPath, newPath);
return await Task.FromResult(true);

For example this are function parameters:

oldPath => \\\SharedFolder\MyFolder

newPath => \\\SharedFolder\RenamedFolder

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download