Solved

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

Posted on 2009-03-30
2
224 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now