Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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