{
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
Textbox1.Text = path.SelectedPath; //取得所選擇的路徑
}
//事先拖曳一個openFileDialog到form裡面
//openFileDialog1的宣告會在form的InitializeComponent()裡
private void btnSelectFile_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = @"c:\";
openFileDialog1.Filter = "Text Files (*.txt)|*.txt|" +
"CSV Files (*.csv)|*.csv|" +
"All Files (*.*)|*.*";
openFileDialog1.FileName = "new.txt";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = false;
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
....
}
Textbox2.Text = file.SafeFileName;
}
以上文章引用自: http://pvencs.blogspot.tw/2012/07/c_17.html
--------------------------------------------------------------------------------------
選擇資料夾
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
textBox1.Text = path.SelectedPath;
選擇檔案
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
textBox1.Text = file.SafeFileName;
以上文章引用自:http://kgood9999.blogspot.tw/2010/09/c_09.html
沒有留言:
張貼留言