txt文件的循环槽线通过FileUpload控件上传 [英] Looping trough lines of txt file uploaded via FileUpload control
本文介绍了txt文件的循环槽线通过FileUpload控件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要选择包含使用FileUpload控件弦线一个简单的.txt文件。但是,而不是实际保存文件我想环槽的每一行文本,并显示在ListBox控件中的每一行。
一个文本文件的例子:
的test.txt
123jhg345
182bdh774
473ypo433
129iiu454
什么是实现这一目标的最佳方式?
我到目前为止有:
私人无效populateListBox()
{
文件上传福= FileUpload1; 如果(fu.HasFile)
{
//循环槽的txt文件,并添加行ListBox1的
}
}
解决方案
私人无效populateListBox()
{
文件上传福= FileUpload1;
如果(fu.HasFile)
{
StreamReader的读者=新的StreamReader(fu.FileContent);
做
{
字符串TEXTLINE = reader.ReadLine(); //做你的编码
//循环槽的txt文件,并添加行ListBox1的 }而(reader.Peek()!= -1);
reader.Close();
}
}
I want to select a simple .txt file that contains lines of strings using a FileUpload control. But instead of actually saving the file I want to loop trough each line of text and display each line in a ListBox control.
Example of a text file:
test.txt
123jhg345
182bdh774
473ypo433
129iiu454
What is the best way to accomplish this?
What I have so far:
private void populateListBox()
{
FileUpload fu = FileUpload1;
if (fu.HasFile)
{
//Loop trough txt file and add lines to ListBox1
}
}
解决方案
private void populateListBox()
{
FileUpload fu = FileUpload1;
if (fu.HasFile)
{
StreamReader reader = new StreamReader(fu.FileContent);
do
{
string textLine = reader.ReadLine();
// do your coding
//Loop trough txt file and add lines to ListBox1
} while (reader.Peek() != -1);
reader.Close();
}
}
这篇关于txt文件的循环槽线通过FileUpload控件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文