Categorias

Selecionando e lendo arquivo TXT

O codigo abaixo abre uma caixa de diálogo(formulário) para que o usuário selecione um arquivo, se for um txt ele exibe o conteúdo.


 



<%
If request.queryString("sid") = "" then
%>
	
Lendo arquivo TXT
Localizar:
<% Else byteCount = Request.TotalBytes RequestBin = Request.BinaryRead(byteCount) Dim UploadRequest Set UploadRequest = CreateObject("Scripting.Dictionary") BuildUploadRequest RequestBin filepathname = UploadRequest.Item("arq").Item("FileName") filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"")) ext =split(filename,".") If ext(1) <> "txt" Then response.write "
Selecione um arquivo com extensão TXT" response.write "
" response.write "
" response.End End if response.write "" response.write "
Local/Nome do Arquivo: " & filepathname & "

Conteúdo:
" Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(filepathname, 1) do while f.AtEndOfStream = false Response.Write(f.ReadLine) & "
" loop f.Close Set f=Nothing Set fs=Nothing End if Sub BuildUploadRequest(RequestBin) PosBeg = 1 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg) boundaryPos = InstrB(1,RequestBin,boundary) Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--"))) Dim UploadControl Set UploadControl = CreateObject("Scripting.Dictionary") Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition")) Pos = InstrB(Pos,RequestBin,getByteString("name=")) PosBeg = Pos+6 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename=")) PosBound = InstrB(PosEnd,RequestBin,boundary) If PosFile<>0 AND (PosFile