| | |
FolderBrowserDialog problems
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 6
Reputation:
Solved Threads: 0
Hi
Has anyone dealt with this windows control ?
I'm trying to get it to work so that the operator can select ANY folder, but it looks like you have to set a RootFolder property to one of several
enumerated options, and if the folder that the user selects is not a subfolder of the chosen RootFolder, then tough luck.
And of course none of the enumerated options for the rootfolder property includes the filesystem root ....................
I've been fighting with it for three days and getting nowhere - has anyone else dealt with this ?
Thanks,
Colm
Has anyone dealt with this windows control ?
I'm trying to get it to work so that the operator can select ANY folder, but it looks like you have to set a RootFolder property to one of several
enumerated options, and if the folder that the user selects is not a subfolder of the chosen RootFolder, then tough luck.
And of course none of the enumerated options for the rootfolder property includes the filesystem root ....................
I've been fighting with it for three days and getting nowhere - has anyone else dealt with this ?
Thanks,
Colm
Are you sure?
If I remember correctly th FolderBrowserDialog, shows you all the folders. Even the system root. Or am I mistaken?
If I remember correctly th FolderBrowserDialog, shows you all the folders. Even the system root. Or am I mistaken?
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
•
•
Join Date: May 2006
Posts: 4
Reputation:
Solved Threads: 1
C# Syntax (Toggle Plain Text)
folderDialog.Description = "Select Folder"; folderDialog.ShowDialog(); if (folderDialog.SelectedPath != string.Empty) txtTargetPath.Text = folderDialog.SelectedPath;
Complete Code.
C# Syntax (Toggle Plain Text)
FolderBrowserDialog folderDialog = new FolderBrowserDialog(); folderDialog.Description = "Select Folder"; if(folderDialog.ShowDialog() == DialogResult.OK) { txtTargetPath.Text = folderDialog.SelectedPath; }
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
•
•
Join Date: May 2006
Posts: 6
Reputation:
Solved Threads: 0
Thanks for your replies.
My code looks like this :
This brings up a dialog box with its root folder set to "my computer"
If I just print the selectedPath to a messageBox it looks fine, but when I try and write it to file it doesn't work.
If I leave the rootFolder at the default (the desktop) and select a folder which exists on the desktop (is a desktop subfolder) then it works fine.
Any ideas ?
Thanks
Colm
My code looks like this :
C# Syntax (Toggle Plain Text)
private void BrowseBtn2_Click(object sender, System.EventArgs e) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); fbd2.ShowNewFolderButton = false; fbd2.RootFolder = Environment.SpecialFolder.MyComputer; DialogResult dr = fbd2.ShowDialog(); if(dr == DialogResult.OK) { userDirText2.Text = fbd2.SelectedPath; this.writeFile("dialog2.txt", userDirText2.Text); } } private bool writeFile(string filename, string str) { try { progressBox.AppendText("Writing // " + filename + " : " + str + "\n"); StreamWriter sw = new StreamWriter(filename); sw.Write(str); sw.Flush(); sw.Close(); return true; } catch (System.IO.IOException) { progressBox.AppendText("IO Error Writing To File.\n"); return false; } }
This brings up a dialog box with its root folder set to "my computer"
If I just print the selectedPath to a messageBox it looks fine, but when I try and write it to file it doesn't work.
If I leave the rootFolder at the default (the desktop) and select a folder which exists on the desktop (is a desktop subfolder) then it works fine.
Any ideas ?
Thanks
Colm
•
•
Join Date: May 2006
Posts: 4
Reputation:
Solved Threads: 1
Your not telling where to write the file, other than jsut a name..try
C# Syntax (Toggle Plain Text)
StreamWriter sw = new StreamWriter(Path.Combine("c:\",filename)); sw.Write(str); sw.Flush(); sw.Close();
If there is an error while writting in your code the file will not close,make sure you close that file if there is an error. otherwise if it stays open youll just get more errors trying to open an already open file.
this is how i typically would do it.
this is how i typically would do it.
C# Syntax (Toggle Plain Text)
private void BrowseBtn2_Click(object sender, System.EventArgs e) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); fbd2.ShowNewFolderButton = false; fbd2.RootFolder = Environment.SpecialFolder.MyComputer; DialogResult dr = fbd2.ShowDialog(); if(dr == DialogResult.OK) { userDirText2.Text = fbd2.SelectedPath; this.writeFile("dialog2.txt", userDirText2.Text); } } private bool writeFile(string filename, string str) { bool pass = false; try { progressBox.AppendText("Writing // " + filename + " : " + str + "\n"); StreamWriter sw = new StreamWriter(filename); sw.Write(str); sw.Flush(); pass = true; } catch (System.IO.IOException) { progressBox.AppendText("IO Error Writing To File.\n"); pass = false; } finally { sw.Close(); } return pass; }
![]() |
Similar Threads
- No time... bitch load of problems (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: Cannot Test For Condition
- Next Thread: compare 2 xml files with csharp
| Thread Tools | Search this Thread |
.net access algorithm alignment array barchart bitmap box broadcast buttons c# c#gridviewcolumn check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing elevated encryption enum event excel file focus forloop form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






