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

  • Thread starter Thread starter Rahul Darkunde
  • Start date Start date
R

Rahul Darkunde

Guest
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"?>
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false"/>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup>
</configuration>

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

xmlDoc.LoadXml(sbFileWriter.ToString());

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



Path to save xml file on my dive
E:\ECX_CSharp_OOPS_FolderStructure_25july\SourceCode\CSharp_GenericXML\bin\Debug\Output_1_1\XML\CompleteXML\middleware\projects\module\com.ofss.digx.module.origination\src\com\ofss\digx\domain\origination\entity\bankpolicytemplate\repository\adapter\Search\DataValue\RateValueData\Config\Test\Date\NumberTo.xml

Continue reading...
 
Back
Top