KevinDeus KevinDeus - 1 year ago 71
C# Question

How to pull the server name from a UNC

Would anyone be able to tell me how to pull the server name out of a UNC?



I apologize but it looks like I need to clarify a mistake: the path actually is more like:


I know this might change things a little

Answer Source

How about Uri:

Uri uri = new Uri(@"\\servername\d$\directory");
string[] segs = uri.Segments;
string s = "http://" + uri.Host + "/" + 
    string.Join("/", segs, 2, segs.Length - 2) + "/";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download