24h購物| | PChome| 登入
2010-12-28 10:25:40| 人氣2,502| 回應0 | 上一篇 | 下一篇

[C#] 列示目錄下的檔案

推薦 0 收藏 0 轉貼0 訂閱站台




程式碼如下:

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            
            List<string> FileItems = new List<string>();

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {                                          ///folderBrowserDialog選取目錄
                foreach (string File in Directory.GetFiles(folderBrowserDialog1.SelectedPath))
                {
                    FileItems.Add(File); //  
                }
            }
            listBox1.DataSource = FileItems;

        }
    }
}

參考資料:

Getting a list of all the files in a directory

C# ListBox in Windows Forms

 

台長: Chris C.S Huang
人氣(2,502) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: C# |
此分類下一篇:[C#] 螢幕像素的座標與顏色
此分類上一篇:[C#] 將影像轉為Byte Array

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文