Converting Files with Long Path Names

Historically, Windows (and before that, DOS) had a maximum path length (MAXPATH) of 260 characters. While this has changed over the years to allow file paths of up to 32,000 characters, many of the underlying components of Windows, including parts of Microsoft.NET, are still bound by the MAXPATH limitation.

Most of the time you never have to think about long path support but it does occasionally occur. A common situation would be having to convert all the files in a directory structure on network attached storage (NAS) created in UNIX or another file system where long paths are supported.


MAXPATH Limitation in Microsoft .NET

Several of the Microsoft.NET System.IO components, namely System.IO.File, System.IO.Directory and System.IO.Path, are all limited by the length of MAXPATH when dealing with files, directories and paths. If you need long path support you will need to P/Invoke the WIN32 File API calls, or use a third-party library that provides long path name support.


All of the conversion methods in PEERNET.ConvertUtility will handle long path names for the input file or folder, output locations, output file name and for the location of the XML results file and logging files.

The one caveat when dealing with long paths is that once the files and directory structures to be converted are copied to the internal staging and working folders in the ConversionWorkingFolder to be processed, those paths need to be less than 255 characters. This staging and working folder limitation is a requirement of the underlying programs, such as Adobe Reader and Microsoft Office, that Document Conversion Service uses to perform conversions. If the file path sent to Document Conversion Service to be converted is longer than MAXPATH that file will gracefully fail to convert.

Keep in mind that even if the input folder path itself is not greater than MAXPATH, the underlying subfolders and file names can create a path that is once they have been moved to the staging and working folders. You can see by this sample directory shown below that the path C:\ALongPathTestFolder we are using as the input folder path will generate file paths longer than MAXPATH.



Setting the ConversionWorkingFolder to Convert Files with Long Path Names

The code sample below shows the settings and options that can be used to control the location of the ConversionWorkingFolder, or the TEMP folder, where the internal staging and working folders are created. Configuring this to a short path off the root of a drive can allow, in most case, for short enough paths internally to convert the files and folders stored in longer paths elsewhere.

Inside the staging and working folders, PEERNET.ConvertUtility uses a date-time stamped subfolder to control the conversion. By default an easy to read folder name similar to Thursday_March_31_2016_10_16_32_AM is used. To shorten this  further, you can set the UseCompressedDateTimeFormat option to true to use the condensed date-time stamp. The condensed version is strictly numerical and similar to 20160331131645, which is much shorter.


IList<PNConversionItem> results = new List<PNConversionItem>();

String strOutputFolder = @"C:\LongPathsTest\Output";

String strCustomTempFolder = @"C:\PN";


// This sample path is 263 chars

String strLogFile = @"C:\LongPathsTest\01234567890123456789012345678901234567890" +

                     "123456789012345678901234567890123456789012345678901234567890" +

                     "123456789012345678901234567890123456789012345678901234567890" + 

                     "12345678901234567890123456789\Output\SIL\" + 



// Directories must exist

if ( !Directory.Exists(strOutputFolder) )





if ( !Directory.Exists(strCustomTempFolder) )





IDictionary<String, String> UserSettings = new Dictionary<String, String>();

UserSettings.Add("UseCompressedDateTimeFormat", "True");


// Convert the folder

results = PNConverter.ConvertFolder(@"C:\ALongPathTestFolder",

                                       true, // include subfolders

                                       "*.*", // filter

                                       String.Empty, // exclude filter

                                       strOutputFolder, // output folder

                                       true, // overwrite existing

                                       true, // remove file ext

                                       true, // create log

                                       "TIFF 200dpi OptimizedColor", // conversion settings

                                       String.Empty, // extensison profile

                                       String.Empty, // MIME profile

                                       UserSettings, // User settings, compressed datetime

                                       String.Empty, // not using remote conversion (DCOM)

                                       strCustomTempFolder, // use custom working folder

                                       strLogFile); // long path to log file