I have an odd issue that I'm hoping someone may be able to explain.
I have written a very short piece of code to demonstrate the issue at the bottom.
I have an app that iterates through folders and there is a good chance that the file paths and names are longer than windows typically allows. I found the workaround of using \\?\
at the start of the path fixed the issue.
However, this fix only works in debug mode or when running the exe directory. If I run it from the start menu it fails with an "illegal characters in path" error.
It appears that both ways of running have the same permissions but there is something that is different. Any ideas?
To replicate:
- Create a new C# form with a single textbox that fills the window
- Add the following code to the Load event:
StringBuilder list = new StringBuilder(); try { foreach (string folder in System.IO.Directory.EnumerateDirectories(@"\\?\C:\")) { list.Append(folder + "\r\n"); } textBox1.Text = list.ToString(); } catch (Exception ex) { textBox1.Text = ex.ToString(); }
- Run in debug; you'll get a list of directories from C.
- Publish it. It will fail with the illegal chars error.
- Locate and run the exe directly. It will work.
Any assistance is appreciated!!