Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

635 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