- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace OpenFileDialogTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btnOpen_Click(object sender, EventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.InitialDirectory = @"C:UserspengshiyuDesktopdestination";
- //设置文件筛选器
- ofd.Filter = "文本文件(*.txt)|*.txt|Word文件(*.doc,*.docx)|*.doc;*.docx|所有文件(*.*)|*.*";
- ofd.FilterIndex = 1;
- ofd.Title = "openFileDialog实例";
- ofd.FileName = "123";
- ofd.ShowHelp = true;
- if (ofd.ShowDialog() == DialogResult.OK)
- {
- string fName = ofd.FileName;
- string fileCon = "";
- StreamReader sr = new StreamReader(fName, Encoding.GetEncoding("gb2312"));
- while ((fileCon = sr.ReadLine()) != null)
- {
- txtShow.Text += fileCon;
- }
- sr.Close();
- }
- }
- }
- }


最后
以上就是聪明薯片最近收集整理的关于C#编程-120:文件选择之OpenFileDialog控件的全部内容,更多相关C#编程-120内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复