Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Is there an easy way in csharp to take a UNC path and resolve its local path

Posted on 2009-02-24
Medium Priority
Last Modified: 2013-12-17
In c#, is there an easy way to take a UNC and resolve its physical location, in other words I have the UNC path \\server\dir1\dir2 and I want to know that that UNC points to C:\dir1\dir2 returned?

I know in c++ there are certain libraries like this one (http://support.microsoft.com/kb/q148391/) that allow for that but I wanted to know if there was an easy way to do it in c#

Question by:SSAFECS
  • 2
LVL 10

Accepted Solution

lucius_the earned 2000 total points
ID: 23725224
.NET doesn't necessarily recognize that the UNC path is local. I don't think there's a method in the Framework to do this, but you can do it yourself even though it won't be simple.

Idea guidelines:
- extract the computer name from your string and compare it with local computer name. If it scores a hit:
- get a collection of all shares on your computer, and find the sharename from your string, replace it with full path name of the share

I can't exactly tell you how to do it right away, it's just an idea that might work.

Author Closing Comment

ID: 31550630
Yea i wound up enumerating the share's via P/Invoke and doing a comparison i just wanted to make sure there wasn't a faster way
LVL 10

Expert Comment

ID: 23728171
Well, maybe there still is a better way... you and I just don't know of it :)
I think this is good, anyway, it sounds like a correct way to go about this problem. Thanks for the points

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Screencast - Getting to Know the Pipeline
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question