views:

1366

answers:

2

On a file path field, I want to capture the directory path like:

textbox1.Text = directory path

Anyone?

+5  A: 

There is a FolderBrowserDialog class that you can use if you want the user to select a folder.

http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx

DialogResult result = folderBrowserDialog1.ShowDialog();
if (result.Equals(get_DialogResult().OK)) {
    textbox1.Text = folderBrowserDialog1.get_SelectedPath();
}

If all you want is to get the direcotory from a full path, you can do this:

textbox1.Text = Path.GetDirectoryName(@"c:\windows\temp\myfile.txt");

This will set the Text-property to "c:\windows\temp\"

Espo
+1  A: 

Well I am using VS 2008 SP1. This all I need:

private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog profilePath = new FolderBrowserDialog();

            if (profilePath.ShowDialog() == DialogResult.OK)
            {
                profilePathTextBox.Text = profilePath.SelectedPath;
            }
            else
            {
                profilePathTextBox.Text = "Please Specify The Profile Path";
            }
MarlonRibunal