5 Replies - 1257 Views - Last Post: 10 January 2013 - 06:56 AM Rate Topic: -----

#1 ravva   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 28-November 12

take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 12:39 AM

im using "FolderBrowserDialog" for locate specific folder(maponline) and want to show message if user select different folder has different name,i dont have idea to take selected folder name to string,please help how to take that name, thank you ,
    FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
        if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
        {
            string foldername;//this name should Slelected folder name by FolderBrowserDialog
		    if(foldername =="maponline")
			{		 
            //action
            //copy data to startup path
            } 
			else
			{
			    messagebox.show("You should select specified folder",)
			}
                
        }


This post has been edited by macosxnerd101: 10 January 2013 - 12:40 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: take selected directory name to string using "FolderBrowserDialog&

#2 LarcaCode   User is offline

  • New D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 22
  • Joined: 30-July 12

Re: take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 12:55 AM

Try this:
...
string folderName = folderBrowserDialog1.SelectedPath;
...



May the MSDN be with you ;)
Was This Post Helpful? 1
  • +
  • -

#3 ravva   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 28-November 12

Re: take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 01:04 AM

no this code gives total path,i want only FolderName
:helpsmilie:
Was This Post Helpful? -1
  • +
  • -

#4 Anthonidas   User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 240
  • Joined: 25-April 11

Re: take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 01:11 AM

I am pretty sure this is a guy, that copies code from everywhere without knowing what he is doing!! How is it possible that he knows how to set up the function ShowDialog() and catch the result but doesn't know the ".SelectedPath"?!
Was This Post Helpful? 0
  • +
  • -

#5 MrShoes   User is offline

  • D.I.C Addict
  • member icon

Reputation: 331
  • View blog
  • Posts: 512
  • Joined: 13-June 12

Re: take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 01:49 AM

Take the selected path, then use String.Split to separate the elements by the '\' character. The last element in the string array will be your folder name. Something like this:

   var elements = folderBrowserDialog1.SelectedPath.Split('\\');
   var folderName = elements[elements.Length - 1];
   MessageBox.Show(folderName);


Was This Post Helpful? 1
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: take selected directory name to string using "FolderBrowserDialog&

Posted 10 January 2013 - 06:56 AM

There is an entire namespace full of methods for dealing with paths, getting the file names, the folder names and so on.

System.IO.Path
http://msdn.microsof...th_methods.aspx
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1