Ola pessoal, sou iniciante em Asp e estou precisando fazer meu arquivo Asp alterar o conteúdo de um arquivo txt, se alguém puder me ajudar fico grato desde já.
Até mais.

Alterar Arquivo Txt
Started By solworks, 01/04/2009, 17:57
2 replies to this topic
#1
Posted 01/04/2009, 17:57
#2
Posted 02/04/2009, 01:30
Ola, amigo
tenho um codigo simples!
[codebox]
<html>
<head>
<title>editando um txt - asp</title>
</head>
<body>
<%
'Cria o fso FSO
Set fso = CreateObject("Scripting.FileSystemObject")
'O parâmetro forReading é utilizado somente para leitura.
ForReading = 1
'Informe aqui o caminho do arquivo TXT
str_arquivo="c:\texto.txt"
Set str_fso = nothing
if Request.form("btsalva") = "salvar" then
'Pega todo o texto
texto = Request.Form("arquivo")
'salva em um novo
Set salvando = fso.CreateTextFile(str_arquivo,True)
salvando.WriteLine texto
Set salvando = nothing
Response.Write "Arquivo Salvo"
end if
'Condição para verificar se o arquivo exite no local informado
If (fso.FileExists(str_arquivo)) Then
%>
<form action="editando_txt.asp" method="post" id="frm_txt" name="frm_txt">
<textarea id="arquivo" name="arquivo" rows="15" cols="60">
<%
'Abertura do fso e loop para ler o arquivo TXT
Set str_fso = fso.OpenTextFile(str_arquivo,ForReading,True)
While (not str_fso.AtEndOfStream)
campo = str_fso.readline
response.write(Server.HTMLEncode(campo) & CHR(13))
wend
%>
</textarea>
<input type="submit" id="btsalva" name="btsalva" value="salvar" />
</form>
<%
Else
response.write "Erro ao tentar encontrar o arquivo"
End If
set fso = nothing
%>
</body>
</html>
[/codebox]
tenho um codigo simples!
[codebox]
<html>
<head>
<title>editando um txt - asp</title>
</head>
<body>
<%
'Cria o fso FSO
Set fso = CreateObject("Scripting.FileSystemObject")
'O parâmetro forReading é utilizado somente para leitura.
ForReading = 1
'Informe aqui o caminho do arquivo TXT
str_arquivo="c:\texto.txt"
Set str_fso = nothing
if Request.form("btsalva") = "salvar" then
'Pega todo o texto
texto = Request.Form("arquivo")
'salva em um novo
Set salvando = fso.CreateTextFile(str_arquivo,True)
salvando.WriteLine texto
Set salvando = nothing
Response.Write "Arquivo Salvo"
end if
'Condição para verificar se o arquivo exite no local informado
If (fso.FileExists(str_arquivo)) Then
%>
<form action="editando_txt.asp" method="post" id="frm_txt" name="frm_txt">
<textarea id="arquivo" name="arquivo" rows="15" cols="60">
<%
'Abertura do fso e loop para ler o arquivo TXT
Set str_fso = fso.OpenTextFile(str_arquivo,ForReading,True)
While (not str_fso.AtEndOfStream)
campo = str_fso.readline
response.write(Server.HTMLEncode(campo) & CHR(13))
wend
%>
</textarea>
<input type="submit" id="btsalva" name="btsalva" value="salvar" />
</form>
<%
Else
response.write "Erro ao tentar encontrar o arquivo"
End If
set fso = nothing
%>
</body>
</html>
[/codebox]
Edição feita por: DiegoCoruja, 02/04/2009, 01:30.
====================================================
Diego M.
Html, CSS, Javascript, Asp, Asp.net, Php, Sql Server, Mysql, Oracle, VB.NET, VBA
====================================================
Diego M.
Html, CSS, Javascript, Asp, Asp.net, Php, Sql Server, Mysql, Oracle, VB.NET, VBA
====================================================
#3
Posted 07/04/2009, 23:24
Obrigado pela ajuda rapaz, acho que esse código resolve o meu problema. até mais.
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)