
加载中…
个人资料
- 博客访问:
- 关注人气:
- 获赠金笔:0支
- 赠出金笔:0支
- 荣誉徽章:
C#编程-120:文件选择之OpenFileDialog控件
(2017-08-14 22:05:01)
-
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();
-
-
}
-
}
-
}
-
}
喜欢
0
赠金笔
加载中,请稍候......