Getting around the 260 chars path limit in Windows

By James Fisk

Just recently I’ve been creating projects in Visual Studio 2010 for SharePoint 2010.  My projects where getting very deep in the filesystem, where the upshot of this is that the file path was getting very long.  To my dismay if you try and deploy a SharePoint solution that contains very long paths (>260 char) it fails.  Now in this day of age, that is not good. 

Now i’ve been reading around and found that the limit is imposed by the WIN32 API, however, I know that NTFS supports file path lengths of 32K. Now that is one hell of a difference.  When we hit this 260 char limit our first reaction is to shorten the file path somehow, but it does not seem right.  Further reading finally led me to a way to get windows to allow file paths upto 32K.

To get windows to allow for path up to 32K you simply prepend the file path with \\?\ and away you go.

Ie copy \\?\c:\<Very long path> \\?\d:\<Very long path>

Now the thing is you can use it in your windows apps to support 32K path lengths and hey presto, a windows app that supports 32K.

Update :-

I found this snippet

The "\\?\" prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.

This was extracted from the MSDN.

So use it with caution.



categoriaUncategorized commento dataFebruary 10th, 2010

About... James Fisk

This author published 12 posts in this site.

Share

FacebookTwitterEmailWindows LiveTechnoratiDeliciousDiggStumbleponMyspaceLikedin

Leave a comment