Hi again
Thanks for the IFileSaveDialog suggestion. In my test I can get the pathname back from that interface for long paths.
Unfortunately I can't get SaveFileDialog to not throw an exception in this example but as far as I know it could be any number of FS layers or filters that are local to my setups
(if that's involved).
Anyway, I can get around it with
internal const string IFileSaveDialog = "84bccd23-5fde-4cdb-aea4-af64b83d78ab";
Urg. Not so easy to use - but I guess it will do.
Thanks - this can be closed as not repeatable unless you need me to try something else?
SaveFileDialog does not allow long pathnames to be returned
In testing our internal tools for handling long pathnames (>MAX_PATH), I've come across the following issue with
System.Windows.Forms.SaveFileDialog
(in .Net 4.8 on Windows 10)
************** Exception Text **************
Message: The given path's format is not supported.
Exception Type: System.NotSupportedException
Source: mscorlib
StrackTrace:
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
at System.Windows.Forms.IntSecurity.DemandFileIO(FileIOPermissionAccess access, String fileName)
at System.Windows.Forms.FileDialog.get_FileName()
at .FileSaveAs
To repeat this, you navigate into a directory which is deeper than MAX_PATH, and click ok to save your file there.
You get the above.
That's a little disappointing considering the amount of effort to manage \?\ we're having to do.
We're using .Net 4.8, where we've replaced System.IO.File.Create / Open / WriteAllText etc to use a NativeMethods.CreateFile from kernel32.dll to support long pathname versions of these functions. (ref. the ms LongPathnames articles and sample code)
Can we fix this SaveFileDialog issue?
Is it fixed in .Net Core out of interest? Not that we can migrate to that quite yet.
Note: You get a slightly different call stack if saveDlg.OverwritePrompt = true, but it boils down to the same issue with CannonicalisePath.
Kind Regards.
Developer technologies Windows Forms
Developer technologies C#
1 answer
Sort by: Most helpful
-
Kenny, Mike 1 Reputation point
2021-02-03T17:41:19.923+00:00