Monday 15 June 2015

c# - FolderBrowserDialog and "." in Pathname -


I'm experiencing a problem using fb. FolderBrowserDialog's selected panel function. Everything is fine, as long as no one is involved in the full path.

For example:

  try {if (arg == 1) fb_dialog.SelectedPath = Path. Gatefulpath (TB_ Path Path); Other fb_dialog.SelectedPath = Path.Getful Path (path.gate directory name (System. Reflection.Assembly.GetExecutingAssembly (.pstation));); } Hold {fb_dialog.RootFolder = System.Environment.SpecialFolder.MyComputer; }   

If the system. Reflection.Assembly.GetExecutingAssembly () The location does not include any "", it navigates to the folder in that folder. Suppose that path is the way: "C: \ program" but if it returns a path "." In this like "C: \ Prog.Test", it will not work, it opens the dialog, gives no error, but prevents the "root" of the file brochure (if specified, otherwise its "desktop").

Any idea how to solve that problem? Because it's quite annoying.

Thanks for the help.

UPDATE: Solved by the keyboard P in this post:

Path.Get directoryname Do not know if you have provided a dot or file in that folder with an extension (such as a file.txt file file or folder?).

If you know that this is a directory, then an alternative solution might be something like this.

  Pthkget Dayrectorinam (system. Riflekshn.asdakshns. The gate Aksepingasmband (). Location + "\\")   

Make sure that < Code> GetDirectoryName know that it's a \ .

updated based on comments replies

This issue Folderbraujhr dialog specific (information above should work in other cases) I was able to reproduce your problem and I managed to find a solution to a relatively hack, but it seems that this is a bug with the FolderBrowserDialog , so it should be enough.

If you include the rootfolder property that you are inputting, it works, for example, if you enter RootFolder on special Folderskmey document and your input C: \ ... \ My documents \ test.dot.folder , it should work, so workarounds special folders enum and sets the first match.

  using (FolderBrowserDialog fbd = new FolderBrowserDialog ()) {fbd.SelectedPath = Path.GetFullPath (Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly (). Location)); // nearest Speshlfolder which matches the input (it can be extended to non-case-Sensist) Enav.GetValues ​​(typeof (Environment.SpecialFolder) in)) {string spath = Environment.GetFolderPath ((Environment .SpecialFolder) SF); If (FDC Selected Contractions (Spath)) {FBI. Rootfolder = (environment specialfolder) sf; break; }} Fbd.ShowDialog (); }    

No comments:

Post a Comment