I am coding some small application. The application will make some file name changes depending on some selections. To open the files I am using the Microsoft.Win32.OpenFileDialog
. Now when I want to open a file with an path longer than 256 characters (I think thats the number) the path gets cut down.
For example I have the following code to open the files:
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = false;
openFileDialog.ValidateNames = false;
if (true == openFileDialog.ShowDialog())
{
//Working with the returned path
}
Then when I want to open a file like this: C:/a/very/long/file/path/with/more/than/256/characters.txt
, the path I get out of the dialog is something like this: C:/a/very/long/file/path/with/more/than/256/CHARAC~1.TXT
The files name tho is 230 characters long.
How can I solve this problem?
Thanks for any help.
As noted in the comments, here is a summary of Peregrine's link.
.reg
file.Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
app.manifest
file and add the following:<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>