C#Winform 打开文件浏览器

cs 复制代码
 private void button1_Click(object sender, EventArgs e) {
            var f = new OpenFileDialog();
            //f.Multiselect = true; //多选
            if (f.ShowDialog() == DialogResult.OK) {
                String filepath = f.FileName;//G:\新建文件夹\新建文本文档.txt
                String filename = f.SafeFileName;//新建文本文档.txt
                this.textBox1.Text = filename +"   "+filepath;
            }
        }
 
        //选取文件夹,并获得路径
        private void button2_Click(object sender, EventArgs e) {
            FolderBrowserDialog f = new FolderBrowserDialog();
            if (f.ShowDialog() == DialogResult.OK) {
                String DirPath = f.SelectedPath;
                this.textBox1.Text = DirPath;//G:\新建文件夹
            }

参考:

C#:打开 文件/文件夹选择框,选取,并获得路径名称_c#带有输入框的选取文件按钮,输入框中显示选取文件的路径-CSDN博客

相关推荐
时光追逐者13 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 70 期(2026年5.01-5.10)
c#·.net·.netcore
zhangjw3413 小时前
第9篇:Java集合框架入门,List详解:ArrayList与LinkedList底层彻底吃透
java·开发语言·list
报错小能手13 小时前
Swift经典面试题汇总
开发语言·ios·swift
得一录13 小时前
TradingAgents金融股票分析的最小实现
开发语言·数据库·人工智能·python
yuanpan13 小时前
Python 与 Conda 编程实战指南:从环境配置到项目运行完整入门
开发语言·python·conda
水木流年追梦13 小时前
大模型入门-应用篇1-prompt技术
开发语言·python·算法·prompt
米丘13 小时前
vue3.x 调度器(Scheduler)实现机制
前端·javascript·vue.js
莫生灬灬13 小时前
ElementUI封装 共91个组件 支持易语言/火山/C#/Python
开发语言·c++·python·ui·elementui·c#
Brilliantwxx13 小时前
【C++】stack_queue与deque模版(模拟实现+认识+对比)
开发语言·c++·笔记·算法·list
ch.ju13 小时前
Java Programming Chapter 3——Subscript of the array
java·开发语言