Winform打開目錄或文件


Winform選擇目錄路徑與選擇文件路徑

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1 {
publicpartialclass SelectFolder: Form {
public SelectFolder()
{
InitializeComponent();
}
privatevoid btnSelectPath_Click(object sender, EventArgs e) //彈出一個選擇目錄的對話框
{
FolderBrowserDialog path = new FolderBrowserDialog();
path.ShowDialog();
this.txtPath.Text = path.SelectedPath;
}
privatevoid btnSelectFile_Click(object sender, EventArgs e) //彈出一個選擇文件的對話框
{
OpenFileDialog file = new OpenFileDialog();
file.ShowDialog();
this.txtFile.Text = file.SafeFileName;
}
}

}winforms 的openFileDialog1能實現 選擇文件夾里面的多個<文件名>一次導入到LISTBOX下呢 !this.openFileDialog1.Multiselect = true;this.openFileDialog1.ShowDialog();foreach(string fName in this.openFileDialog1.FileNames){ this.listBox1.Items.Add(fName);}讀取選擇好的,文件全地址及名稱

OpenFileDialog openfiledialot = new OpenFileDialog();

openfiledialot.ShowDialog();

this.textBox1.Text = openfiledialot.FileName.ToString();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM