الاثنين، 21 نوفمبر 2011

FolderBrowserDialog Sample

Prompts the user to select a folder. This class cannot be inherited.

to read More go to MSDN


example


Sample Description
When we press in the browse button the FolderBrowserDialog show dialog to
select directory and when we press on the get files button we get all files
hosted in the directory and display it's name in listbox


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            ChooseFolder();
        }
        public void ChooseFolder()
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnGetFiles_Click(object sender, EventArgs e)
        {
            listBox1.DataSource = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
        }


       
     
    }
}
 

0 التعليقات: