Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

marvazoler

Como ler TXT

Recommended Posts

precisa usar FSO

 

exemplo

 

Num TXT com este conteúdo.
---------------------------------------------------------------------------------
Freecode|http://www.freecode.com.br
MSDN|http://www.msdnbrasil.com.br
TechNet|http://www.technetbrasil.com.br
Freecode|http://www.freecode.com.br/drArtigos
Microsoft|http://www.microsoft.com.br
Forum|http://www.freecode.com.br/forum
Artigos|http://www.freecode.com.br/drArtigos
Tutoriais|http://www.freecode.com.br/tutorias
---------------------------------------------------------------------------------

<html>
<head>
<title>Busca em FSO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#CCCCCC">
<form method="post" action="busca_fso_action.asp">
<table width="650" cellpadding="1" cellspacing="0" border="1" align="center">
<tr>
<td> <div align="center"><font color="#666699" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>::
Entre com a pesquisa
</strong></font></div></td>
</tr>
<tr>
<td><font color="#666699" size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">Pesquisar:</font>
<input name="pesquisa" type="text" id="pesquisa" size="20" maxlength="50">
 
<input type="submit" name="Submit" value="buscar">
<input type="hidden" name="botao" value="true">
</strong></font> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
código

<% Option Explicit
' declaro as variaveis
Dim fso, fsofile,varpesquisa,varcaminho,contador,linha,icampo

'
recupero as variaveis
varpesquisa
=Trim(request.form("pesquisa"))
' retiro o aspas simples
varpesquisa=Replace(varpesquisa,"'","")

' crio o FSO

Set fso=Server.createobject("
Scripting.FileSystemObject")
' abro o arquivo txt
varcaminho=Server.MapPath("
texto.txt")
Set fsofile=fso.opentextfile(varcaminho,1,true,false)
if fsofile.AtEndOfStream = true then
response.Redirect("
busca_fso_form.asp?msgeof=1")
else
contador=0
while not fsofile.AtEndOfStream = true
linha=fsofile.readline
icampo=Split(linha,"
|",-1,1)
if LCase(varpesquisa) = LCase(icampo(0)) then
response.Write("
<a href='"&icampo(1)&"'>"& icampo(0)&"</a><br>")
contador=contador + 1
end if
wend
response.Write("<br>
Total de registros encontrados:") &contador
end if
fsofile.close
Set fsofile=nothing
Set fso= nothing
%>

 

lembrando que existem mais exemplos no fórum, postei vários

Compartilhar este post


Link para o post
Compartilhar em outros sites

existem outros exemplos também, e vc pode implementar para sua necessidade também

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.