c# 选择文件夹或文件
2019-07-15 09:07:12 qq_43026206 阅读数 15

选择文件和选择文件夹使用的是不同的两个方法:
1、选择文件使用OpenDialog

    OpenFileDialog dialog = new OpenFileDialog();
    dialog.Title = "选择属性文件";
    dialog.Filter = "Excel|*.xls|Excel|*.xlsx";
    dialog.RestoreDirectory = true;
    if (dialog.ShowDialog() == DialogResult.OK)
    {
         textBox1 =  dialog.FileName;
    }

2、选择文件夹使用FolderBrowserDialog

FolderBrowserDialog folderDialog = new FolderBrowserDialog();
folderDialog.Description = "选择路径";
if (folderDialog.ShowDialog() == DialogResult.OK)
{
      textBox1.Text = folderDialog.SelectedPath;
}
2018-04-04 17:17:20 newbie_xymt 阅读数 2385

本文转载连接: http://www.cnblogs.com/qc-id-01/p/7489021.html


 //选择文件
2 OpenFileDialog dialog = new OpenFileDialog();
3 dialog.Multiselect = true;//该值确定是否可以选择多个文件
4 dialog.Title = "请选择文件夹";
5 dialog.Filter = "所有文件(*.*)|*.*";
6 if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
7 {
8     string file = dialog.FileName;
9 }
复制代码

选择文件夹

复制代码
1  FolderBrowserDialog dialog = new FolderBrowserDialog();
2             dialog.Description = "请选择文件路径";
3             dialog.SelectedPath = path;
4             //dialog.RootFolder = Environment.SpecialFolder.Programs;
5             if (dialog.ShowDialog() == DialogResult.OK)
6             {
7                 string foldPath = dialog.SelectedPath;
8 }

2017-09-07 12:03:00 weixin_30764137 阅读数 9
选择文件
1 //选择文件
2 OpenFileDialog dialog = new OpenFileDialog();
3 dialog.Multiselect = true;//该值确定是否可以选择多个文件
4 dialog.Title = "请选择文件夹";
5 dialog.Filter = "所有文件(*.*)|*.*";
6 if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
7 {
8     string file = dialog.FileName;
9 }

选择文件夹

1  FolderBrowserDialog dialog = new FolderBrowserDialog();
2             dialog.Description = "请选择文件路径";
3             dialog.SelectedPath = path;
4             //dialog.RootFolder = Environment.SpecialFolder.Programs;
5             if (dialog.ShowDialog() == DialogResult.OK)
6             {
7                 string foldPath = dialog.SelectedPath;
8 }

 

posted on 2017-09-07 12:03 高软玩家 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/qc-id-01/p/7489021.html

2013-10-14 01:20:57 pan93529 阅读数 361
2017-09-07 12:58:09 liangbaihang 阅读数 148
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestFolderBrowserDialog
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter="所有文件(*.*)|*.*";
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file=fileDialog.FileName;
                MessageBox.Show("已选择文件:" + file,"选择文件提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        private void btnPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string foldPath = dialog.SelectedPath;
                MessageBox.Show("已选择文件夹:" + foldPath, "选择文件夹提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("Explorer.exe","c:\\windows");
        }
    }

}

转自:http://www.cnblogs.com/szytwo/archive/2012/03/21/2410041.html

没有更多推荐了,返回首页