打开文件操作。

newsea008 2004-06-29 01:37:20
问题如下:
有一个文本框和两个按钮,一个label控件。
1.其中一个按钮和文本框连用,起选择文件的作用,选择的文件路径显示在文本框中。
2.另一个按钮以文本格式打开文本框中所选的文件,并在label中显示其内用。


第一步已经实现,第二步如何做?请指教!!
...全文
161 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
eagle0205 2004-08-07
  • 打赏
  • 举报
回复
FileInfo myFile=new FileInfo(FileName);

StreamReader sr=myFile.OpenText();
string nextLine;
while((nextLine = sr.ReadLine())!=null)
{

Add(nextLine);
}
sr.Close();
brightheroes 2004-06-29
  • 打赏
  • 举报
回复
另一个按钮以文本格式打开文本框中所选的文件,并在label中显示其内用
--修改楼上的代码

private void button1_Click(object sender, System.EventArgs e)
{
String path="c:\\xx.txt";
StreamReader fl=new StreamReader(@path);
this.label1.Text = fl.ReadToEnd();
fl.Close();
}
nocolor 2004-06-29
  • 打赏
  • 举报
回复
using System.IO;

private void button1_Click(object sender, System.EventArgs e)
{
String path="c:\\xx.txt";
StreamReader fl=new StreamReader(@path);
String text=fl.ReadLine();
while(text!=null)
{
label1.Text=text;
text=fl.ReadLine();
}
}
newsea008 2004-06-29
  • 打赏
  • 举报
回复
期待中。。。。。。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧