Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to grab folder browser selection and place in a text box using C sharp?

Posted on 2009-03-30
2
Medium Priority
?
232 Views
Last Modified: 2013-12-17
I keep getting error - cannot implicitly type 'string' to System.Environment.Special Folder for the following cmdBrowseFolder_Click - with the highlight on @sTo;

Also for the second cmdBrowseFile_Click private void, I keep getting an error - cannot implicitly type 'string' to System.Windows.Forms.TextBox with the highlight on of.FileName;
Is there anyway I could have it open the file dialog to a specific file path?

I'm new to C# too so I apologize.
private void cmdBrowseFolder_Click(object sender, EventArgs e)
        {
            string sTo;
            sTo = txtTo.Text;
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "Select a folder";
            fbd.RootFolder = @sTo;
            //fbd.SelectedPath = @"C:\";
            fbd.ShowNewFolderButton = true;
            if (fbd.ShowDialog(this) == DialogResult.OK)
            {
                MessageBox.Show(fbd.SelectedPath);
            }
 
        }
 
private void cmdBrowseFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.Filter = "All File Types(*.*)|*.*";
            of.RestoreDirectory = true;
            if (of.ShowDialog() == DialogResult.OK)
            {
                txtRevit = of.FileName;
 
            }
 
        }

Open in new window

0
Comment
Question by:stephenlecomptejr
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 24023981
I suspect you actually want to set the SelectedPath property rather than the RootFolder property.

      fld.SelectedPath = sTo;           // not quite sure why you had the @ symbol in there

The problem with the second method is that you are trying to assign a value to the textbox itself rather than to the Text property of the TextBox, it should say:

    txtRevit.Text = of.FileName
0
 
LVL 1

Author Closing Comment

by:stephenlecomptejr
ID: 31564575
Thanks for the quick reply.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question