How to Browse a particular folder - c#

I have a folderBrowserDialog control and i have a button named click
i did like this way
private void click_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowDialog();
}

If what you wish to accomplish is to automatically display a folder of your choice whenever the FolderBrowserDialog is shown, then you can use the following code:
private void click_Click(object sender, EventArgs e)
{
FolderBrowserDialog f = new FolderBrowserDialog();
f.Description = "Please browse to, and select a folder";
f.RootFolder = #"C:\Name Of Folder You Want Displayed\";
using(f)
{
if(f.ShowDialog() == DialogResult.OK)
{
// Do something when the user clicks OK or Open.
}
}
}
Or, you could simply add a FolderBrowserDialog to your Form from the Visual Studio ToolBox and click on the Properties tab, and then click the down arrow to the right-hand side of the 'Root Folder' option and select one of the listed folders from the drop-down menu.
Hope this helps.

You can use a custom build Folder Browser Dialog/Control for this. Try this: http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx

Related

How can I use FolderBrowserDialog in wpf?

private void btnRadarFolder_Click(object sender, RoutedEventArgs e)
{
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
if(result.)
}
}
The first time I tried to use the System.Windows.Forms.FolderBrowserDialog I got error that Forms don't exist. so I installed the ookii-dialogs-wpf package and once installed the errors are gone but I'm not sure what to do next. The variable result don't have an OK or any properties to continue with the dialog.
When I click the button, it's opening the dialog browser like in the old vista style, but I'm not sure how to handle it in the button/s click event.

I want the last folder in FolderBrowserDialog to be open by default in C#

This is my source code in C#:
private void button11_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = Directory.GetCurrentDirectory() + "\\Slides";
DialogResult result = fbd.ShowDialog();
}
When you click on the button the FolderBrowserDialog will be shown. My problem is that the last folder named Slides here is not open by default in the ShowDialog form.
I want something like this when the Dialog is shown:
And not like this while sub directories of Slides are closed:
Notice: there can be different folders in the Slides directory.

How do I show a directory path in a textbox when selected by the user?

First, I am using Visual Studio 2013 and coding in C# to develop a Windows Form Application. I have added the "System.IO" namespace.
I need to show a directory path in a textbox when selected by the user.
The code works correctly to where the user selects a folder from a popup
and presses the OK button, which then displays the number of files within
that folder -- but the folder path does NOT get displayed as I desired.
Code looks like this:
private void button1_Click(object sender, EventArgs e)
{
//
// This event handler was created by clicking the button in the application GUI.
//
DialogResult button1_Click = folderBrowserDialog1.ShowDialog();
if (button1_Click == DialogResult.OK)
{
//
// The user selected a folder and pressed the OK button.
// A message pops up and identifies the number of files found within that folder.
//
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
MessageBox.Show("Files found: " + files.Length.ToString(), "Message");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string path;
path = folderBrowserDialog1.SelectedPath;
// folderBrowserDialog1.ShowDialog(); // NOT SURE ABOUT USING THIS!
textBox1.Text = path;
}
You could just add this to the end of your button1_Click method (inside the if block):
textBox1.Text = folderBrowserDialog1.SelectedPath;

Click event for Report Viewer?

Is there a click event/property for the Report Viewer which can return to me what they are clicking on?
The report designer is limited to:
Go to Report
Go to bookmark
Go to url
My report has a field with a file name, I would like to write into my Double Click Event to open the containing folder on DoubleClick.
I dont need help with the code for opening the folder, just on getting what is being doubleclicked on so I can open the correct folder. Something like
private void rptvReport_DoubleClick(object sender, EventArgs e)
{
MessageBox.Show(rptvReport.**CURRENTITEM**.text);
}
In your report set the textbox action to "go to Url" and the expression for the url set it to:
="http://someaction?rowid="+Trim(Str(Fields!SomeIdField.Value))
Then in your form use the "Hyperlink" event of the report viewer control:
uxReportViewer.Hyperlink += uxReportViewer_Hyperlink;
And in the eventhandler:
void uxReportViewer_Hyperlink(object sender, HyperlinkEventArgs e)
{
Uri link = new Uri(e.Hyperlink);
if (link.Authority == "someaction")
{
e.Cancel = true; //Cancel the event to avoid opening the browser
char[] sep=new char[] {'='};
var param=link.Query.Split(sep);
string rowId=param[1];
MessageBox.Show("You clicked on Id: "+rowId.ToString());
}
}
You can extend this for different actions and more than one parameter

Windows Forms FolderBrowserDialog hangs the application

With winforms, when I right click on a folder or try to delete a folder within the FolderBrowserDialog the window becomes irresponsive and I've to force-close it.
Here's the code:
private void btnOpenFileDialog_Click(object sender, EventArgs e)
{
folderBrowserDialog1.SelectedPath = txtBoxLog.Text;
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog1.ShowDialog()==DialogResult.OK)
{
txtBoxLog.Text = folderBrowserDialog1.SelectedPath;
}
}
The problem was system wide, so the control was correctly behaving in an incorrect way (irony).

Categories