20
Vote

Support for UNC paths

description

Support for long UNC paths (using the special "\UNC\" prefix) would be welcome. I see from the code that there is currently only support for non-UNC ("\?\") paths.
 
 
Thanks.

file attachments

comments

jfree wrote Apr 9, 2010 at 6:30 PM

thanks for the suggestion

d3j409 wrote Oct 26, 2010 at 3:30 PM

Here is a proposed modification to support UNC Paths.

ryannewington wrote Mar 11, 2011 at 4:47 AM

adding UNC path support is pretty straightforward. The following code will allow support for supplying \server\share paths to this library

Add the following to NativeMethods

internal const string LongPathUNCPrefix = @"\?\UNC\";

Replace the following functions in LongPathCommon.cs
    private static string AddLongPathPrefix(string path) {
       if (path.StartsWith (@"\\")) { // if we have been passed a UNC style path (server) prepend \\?\UNC\ but we need to replace the \\ with a single \
            return NativeMethods.LongPathUNCPrefix + path.Substring(2);
        }
        else //assume a standard path (ie C:\windows) and prepend \\?\ to it
        {
            return NativeMethods.LongPathPrefix + path;
        }
    }

    internal static string RemoveLongPathPrefix(string normalizedPath) {

        if (normalizedPath.StartsWith(NativeMethods.LongPathUNCPrefix)) // if we have been supplied a path with the \\?\UNC\ prefix
        {
            return @"\\" + normalizedPath.Substring(NativeMethods.LongPathUNCPrefix.Length);
        }
        else if (normalizedPath.StartsWith(NativeMethods.LongPathPrefix))  // if we have been supplied with the \\?\ prefix
        {
            return  normalizedPath.Substring(NativeMethods.LongPathPrefix.Length);
        }

        return normalizedPath;

    }