C#: Any way to get around the 260 character limit of a fully qualified path?

13.7k Views Asked by At

Possible Duplicate:
Why does the 260 character path length limit exist in Windows?

I'm trying to figure out a way to get around this dreaded 260 character fully qualified path limit and at the same time I wonder why the hell is there a path limit to begin with!? I know to some people 260 seems to be "a lot", but it truly isn't since I ran into this issue.

Basically:
Why must there be a character limit?
How does one get around it?

3

There are 3 best solutions below

4
On BEST ANSWER

Use the \\?\ UNC prefix to break out of "DOS mode" for paths. The max length for UNC paths is 32k characters.

More info here: http://msdn.microsoft.com/en-us/library/aa365247.aspx

0
On

Well, first, this has nothing to do with C# in particular, and everything to do with the Windows API, wherein that limit resides. :)

Take a look at this question and its answers, which will lead you to MSDN: Naming Files, Paths, and Namespaces

Unicode file paths (described in the answers to the question, and the MSDN article) may be as solution, with some caveats.

0
On

From the MSDN:

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".