Discussion:
Writing xml.ResponseText to file
(too old to reply)
w***@gmail.com
2005-07-20 14:27:28 UTC
Permalink
Hello, I'm having some problems writing out xml.ResponseText to a text
file. I can send it to a web browser using Response.Write, but I can
not write it out to a text file. It's not a permissions issue, the
file gets created without a problem and if you write a line of plain
text to the file, it works perfectly. I tried casting xml.ResponseText
to a string, but that did not work either. Is there anyway I can do
this?

<%
Const ForWriting = 2
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://xxxx", False
xml.Send
set tfile=FSO.CreateTextFile("c:/pathtofile.asp", true)
'response.write xml.ResponseText <--- Works
'tfile.WriteLine "Hello World" <---- Works
tfile.WriteLine(test)
tfile.close
set fso = nothing
%>
Torgeir Bakken (MVP)
2005-07-20 14:28:02 UTC
Permalink
Post by w***@gmail.com
Hello, I'm having some problems writing out xml.ResponseText to a text
file. I can send it to a web browser using Response.Write, but I can
not write it out to a text file. It's not a permissions issue, the
file gets created without a problem and if you write a line of plain
text to the file, it works perfectly. I tried casting xml.ResponseText
to a string, but that did not work either. Is there anyway I can do
this?
<%
Const ForWriting = 2
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://xxxx", False
xml.Send
set tfile=FSO.CreateTextFile("c:/pathtofile.asp", true)
'response.write xml.ResponseText <--- Works
'tfile.WriteLine "Hello World" <---- Works
tfile.WriteLine(test)
tfile.close
set fso = nothing
%>
Hi,

If I am not mistaken, you need to open the text file as unicode (and
not as ascii like you do now) to make this work...

See here for more info:

From: Torgeir Bakken (Torgeir.Bakken-***@hydro.com)
Subject: Re: XMLHTTP Need help
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-03-25 11:40:22 PST
http://groups.google.co.uk/group/microsoft.public.scripting.vbscript/msg/91dd1a885ce044d7?dmode=source
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
w***@gmail.com
2005-07-20 14:39:18 UTC
Permalink
Also, I have tfile.WriteLine(test) in there, I had another variable
casting it to a string. tfile.WriteLine xml.ResponseText doesn't work
either.

Almost forgot, the error I get is:

Invalid procedure call or argument on the line with the tfile.WriteLine
xml.ResponseText
Suresh
2005-07-20 14:49:11 UTC
Permalink
oh okay, ignore my previous post then ...

Suresh
2005-07-20 14:45:58 UTC
Permalink
Post by w***@gmail.com
tfile.WriteLine(test)
I believe that the problem is the variable [test] popping out of
nowhere ... ; )

It should be:
tFile.WriteLine xml.ResponseText

( Use [Write] instead of [WriteLine] if you don't want a CRLF inserted
at the end)


- Suresh
Loading...