Asp.Net - Ler arquivos .TXT
protected void Button2_Click(object sender, EventArgs e)
{
string caminho = Server.MapPath("~\\Arquivos\\dados.txt");
StreamReader srLeitor = File.OpenText(caminho);
srLeitor.BaseStream.Seek(0, SeekOrigin.Begin);
string cod = "", nome = "", cidade = "", linha = "";
while (srLeitor.Peek() > -1)
{
linha = srLeitor.ReadLine();
cod = linha.Substring(0, 4);
nome = linha.Substring(4, 20);
cidade = linha.Substring(27, 7);
ListBox2.Items.Add(cod);
ListBox3.Items.Add(nome);
ListBox4.Items.Add(cidade);
}
srLeitor.Close();
}
Comentários
Postar um comentário