Solved

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

Posted on 2009-03-30
2
223 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
Comment Utility
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
Comment Utility
Thanks for the quick reply.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

10 Experts available now in Live!

Get 1:1 Help Now