重庆熊猫 Loading

Winforms选择文件、文件夹

更新记录:
2022年7月13日 新增选择多个文件。
2022年5月28日 发布。

选择文件(单选)

this.openFileDialog1.Filter = "PDF文件|*.pdf";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
    //获得用户选择文件
    string importFilePath = this.openFileDialog1.FileName;
}
else
{
    //提示用户
    this.alertControl1.Show(this, "温馨提示","您取消了选择文件");
}

选择文件(多选)

this.openFileDialog1.Filter = "PDF文件|*.pdf";
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
    //开启多选
    this.openFileDialog1.Multiselect = true;
    //获得用户选择文件
    string[] importFilesPath = this.openFileDialog1.FileNames;
}
else
{
    //提示用户
    this.alertControl1.Show(this, "温馨提示","您取消了选择文件");
}

选择文件夹(单选)

if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
    //获得用户选择文件夹
    string userSelectPath = this.folderBrowserDialog1.SelectedPath;
}
else
{
    //提示用户
    this.alertControl1.Show(this, "温馨提示","您取消了选择文件夹");
}

选择文件夹(多选)

请看这篇:
https://www.cnblogs.com/cqpanda/p/16474839.html

posted @ 2022-07-13 15:12  重庆熊猫  阅读(111)  评论(0编辑  收藏  举报