C#编程-120:文件选择之OpenFileDialog控件_彭世瑜_新浪博客
【摘要】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using ...
- 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:\Users\pengshiyu\Desktop\destination";
- //设置文件筛选器
- 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();
- }
- }
- }
- }
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/109661873
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)