Net Core 3.1 access directories on another server

66 views Asked by At

I am trying to create some code where I can navigate some directories on another server.

To do this I am trying to pass in the server name to DirectoryInfo class. Thus, my code is:

string serverPath = @"\someServer\c$\folder\folder\";

var serverDirectories = new DirectoryInfo (serverPath);
var directories= directories.GetDirectories();

The problem is when I try to get the directories it is not working, and I am seeing c in the path that I trying to get to. So, I tried using Server.MapPath, but this doesn't exist in .Net Core 3.1.

So, my question how do get a list of directory and files from another server in .Net Core 3.1?

1

There are 1 answers

1
Valuator On

You need a double blackslash \\ before the server name when accessing a remote server. Change your path to:

string serverPath = @"\\someServer\c$\folder\folder\";

A single blackslash references the root of your local filesystem, which is C:, so it looks for `C:\someServer\c$\folder\folder\ instead.