I am facing the long path issue while saving the XML file at path length > 260 character through the C# windows application on Windows 10 RRS feed

  • Question

  • I am developing one application using the C# windows forms to save XML file at particular folder on computer drive.But currently i have to save xml file at path having length > 260 character but its give me an error as below 

    The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

    so to avoid this i did the external setting to enable the long path in windows 10 , but still same issue getting as above.

    For xternal setting used following steps : 

    1. Hit the Windows key, type gpedit.msc and press Enter.
    2. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS.
    3. Double click the Enable NTFS long paths option and enable it

    Then I have added one tag in app.config file as follow to set longpath flag as follow

    <?xml version="1.0"?>
        <AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false"/>
    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup>  

    after adding above tag in app.config , I just add @"\\?\"  before the filename in xmldocument.save method 


    xmlDoc.Save(@"\\?\" + "path having the length > 260 characters"+ ".Xml");

    Path to save xml file on my dive

    Tuesday, September 10, 2019 12:43 PM

All replies

  • Did you add an app manifest as well? Based upon the MS blog you have to opt into the functionality as well and that requires an app manifest.

    You don't need the appsettings for 4.6.2+ You only need those for previous versions that are running on a 4.6.2 or newer runtime. You can remove them.

    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, September 10, 2019 2:49 PM