您当前的位置: 首页 >  c#

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#编程-120:文件选择之OpenFileDialog控件_彭世瑜_新浪博客

彭世瑜 发布时间:2017-08-14 22:05:01 ,浏览量:1

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace OpenFileDialogTest
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnOpen_Click(object sender, EventArgs e)
  21.         {
  22.             OpenFileDialog ofd = new OpenFileDialog();
  23.             ofd.InitialDirectory = @"C:\Users\pengshiyu\Desktop\destination";
  24.             //设置文件筛选器
  25.             ofd.Filter = "文本文件(*.txt)|*.txt|Word文件(*.doc,*.docx)|*.doc;*.docx|所有文件(*.*)|*.*";
  26.             ofd.FilterIndex = 1;
  27.             ofd.Title = "openFileDialog实例";
  28.             ofd.FileName = "123";
  29.             ofd.ShowHelp = true;
  30.             if (ofd.ShowDialog() == DialogResult.OK)
  31.             {
  32.                 string fName = ofd.FileName;
  33.                 string fileCon = "";
  34.                 StreamReader sr = new StreamReader(fName, Encoding.GetEncoding("gb2312"));
  35.                 while ((fileCon = sr.ReadLine()) != null)
  36.                 {
  37.                     txtShow.Text += fileCon;
  38.                 }
  39.                 sr.Close();
  40.  
  41.             }
  42.         }
  43.     }
  44. }
C#编程-120:文件选择之OpenFileDialog控件 C#编程-120:文件选择之OpenFileDialog控件
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0568s