FileSystemObject

HI

I am trying to run the below code:

Dim objXMLHTTP, xml

Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://webserver/magazine1/index.asp", False
xml.Send
value =  xml.responseText
Set xml = Nothing


Set objFile = Server.CreateObject("Scripting.FileSystemObject")
Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), 2, True, 0)
objTStream.Write(value)
 
Set objFile = nothing

and I getting the following error :

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument

/magazine1/inco.asp, line 32

the line 32 is the one that has the line :objTStream.Write(value)

if I do a response.write(value) it prints all the HTML retrieved but it is not able to write to the HTML file I checked if the file is found ? it is found and I do have permissions !!!!

Please help
LVL 1
marounkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Michel SakrConnect With a Mentor Commented:
although it might garble the output...

http://support.microsoft.com/support/kb/articles/q259/3/52.asp

you can also replace the french characters:

value=replace(value,"e","&#130") 'e = e with accent aigu /

do it to all the french characters you can find their ascii dec values here http://members.tripod.com/~plangford/ or by using the asc function

rgrds
0
 
jitgangulyCommented:
Use writeline

objTStream.WriteLine value
 
0
 
Michel SakrCommented:
Hmm it should work actually..

try to change the value to something else for testing.. like "xyz"

also set the permissions to full controle.. fso sometimes chokes for less..
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Michel SakrCommented:
2cents: If nothing works try to write to the stream by chunks..
0
 
jitgangulyCommented:
Actually try this also
Instead of this line

Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), 2, True, 0)

use constants, like

Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), ForWriting, True, TristateFalse)
0
 
Michel SakrCommented:
>use constants, like

Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), ForWriting, True, TristateFalse)

He'll need to include the adovbs.inc ... it's the same, better to do as he did..
0
 
Michel SakrCommented:
>use constants, like

Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), ForWriting, True, TristateFalse)

He'll need to include the adovbs.inc ... it's the same, better to do as he did w/o constant names..
0
 
Michel SakrCommented:
The IUSR_Webservername is the one that you should grant full permissions to the file, if anonymous account is enabled..
0
 
AzraSoundCommented:
try:

Call objTStream.Write(value)

or

objTStream.Write value
0
 
preinskoCommented:
Unless something changed recently xmlhttp returns a xml stream.  Typically the reponse content is written to a data island.

strOutputResponse = objXMLReq.responseText

in the body of html document
<p>Response XML:</p>
<div id=divOutputResponse><%=strOutputResponse%></div>
There is a sample in the xml sdk.

0
 
puranik_pCommented:
the error you are getting .. "Invalid procedure call or argument " appears in these cases..
1. you are using parantheses for a procedure call
(exactly thats what you are doing.!)
objTStream.Write(value) will cause error.
objTStream.Write value  will work.

2. you are calling the function with more than or less than number of arguments.
(which is not the case with you.)
so relax!!

 
0
 
marounkAuthor Commented:
Thnx all for replying but nothing worked !

If I write for example a string "hello world" it works but when I try to write the variable "value" it does not.

I gave the I_user permissions to the whole directory but still no sign of life


silvers5 could you please explain how to write chunks ???
or is there any other altenative ?

0
 
AzraSoundCommented:
everything looked ok except for how you called the function with parentheses...at least, that is something you NEED to fix because it should be generating an error.
0
 
marounkAuthor Commented:
would it help if you knew that the data size :30287
I did  a Response.write(len(value)) it returned 30287 !!!

I think the problem is with the size of Data because when I run objTStream.Write "hello world" it worked !!!!
0
 
AzraSoundCommented:
thats near the integer data type limit, so perhaps that is an issue...

>>when I run objTStream.Write "hello world" it worked

also notice you properly called the method here.  try each of the following:

Call objTStream.Write(value)
objTStreamWrite value
Call objTStream.Write(Left(value, 20000))
objTStream.Write Left(value, 20000)

just to see if it is indeed size that is hurting you.
0
 
Michel SakrCommented:
by chunks..
Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), 8, True, 0) '8 is for appending

ZLength = Len(value)
for x = 1 to ZLength
valueX = Mid(value,x,3000)
x = x + 3000
objTStream.Write(valueX)
next
valueX = right(value,ZLength - (ZLength MOD 3000)
'the above line will write the last chunk that was bypassed, if it's less than 3000 characters, MOD returns the remainder of a division between 2 numbers
objTStream.Write(valueX)
....


rgrds
0
 
Michel SakrCommented:
errata:
valueX = right(value,ZLength - (ZLength MOD 3000)

should have a closing parantheses and like this

valueX = right(value,(ZLength MOD 3000))
0
 
preinskoCommented:
Silvers5 stated this before!!
The IUSR_Webservername must have write permissions. I notice that what you say regarding permissions is
>>it is found and I do have permissions !!!!
Here you stated I do have permissions not that the web server has permissions.

It makes no difference if you have permissions unless your application is using NT Authentication.

I just took your code and added to a xmlhttp page I happened to have, and wrote to a folder I have setup for writing to.  The response from the remote server was written to the file with no problem. So there is nothing functionally wrong with your code. The only thing left is permissions.

Please go to the folder in question
Right click
Select the security tab
Look at the list and see if there is an entry for
IUSR_WebServerName  WebServerName should be the name of your web server.
If there is check the permissions, write permissions are not given by default (normally) if the write checkbox is off put a check there.
If the IUSR_WebServerName does not appear in the list then add it and give it write permissions.
Select Apply and run your app I think it will work now.
If it works please give the points to Silvers5 since he twice mentioned permissions to you.  

Hope this helps because I am totally stumped on this one.




0
 
marounkAuthor Commented:
Check this out :

I have tried the following :
objTStream.Write Left(value, 5000) it worked , then I tried objTStream.Write Left(value, 10000) it failed and it gave the error it seems that it can not write huge blocks of data !

0
 
marounkAuthor Commented:
Hi Preinsko
I already gave permissions to the I_user to full control but it did not change ! the problem is with the amount of data written .thnx for your help

0
 
Michel SakrCommented:
maroun, I posted you a code on how to do it.. you can add it in a function for repeated reusability..

rgrds
0
 
marounkAuthor Commented:
silvers5

I used your code and it failed on a point !!! it wrote like 10 % to the file then it failed then I tried to do the following :

objTStream.Write Left(value, 6100) it worked
objTStream.Write Left(value, 6200) it worked
objTStream.Write Left(value, 6300) it worked
objTStream.Write Left(value, 6400) it failed !!
0
 
Michel SakrCommented:
or is it Tarek ;o)
0
 
Michel SakrCommented:
Try it like this:

appending will be needed here.. not in the previous code..

ZLength = Len(value)
for x = 1 to ZLength
Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), 8, True, 0) '8 is for appending
valueX = Mid(value,x,6000)
x = x + 6000
objTStream.Write(valueX)
Set objStream = nothing
next
Set objTStream = objFile.OpenTextFile(Server.MapPath("indexof.htm"), 8, True, 0)
valueX = right(value,ZLength - (ZLength MOD 6000)
'the above line will write the last chunk that was bypassed, if it's less than 6000 characters, MOD
returns the remainder of a division between 2 numbers
objTStream.Write(valueX)
Set ObjStream = nothing
....



0
 
marounkAuthor Commented:
fails too ~!!! this problem is driving me nuts ~~
0
 
Michel SakrCommented:
what's the error now?
0
 
marounkAuthor Commented:
I know where the problem is :

it is failing on strange chracters , the asp file is reading french data from the Database the write is failing on the character e if I change it e it will continue to write until another french specific character where it fails!

0
 
Michel SakrCommented:
can you post the url you're fetching? or email it to silvers@rocketmail.com(if it's on the web)
0
 
Michel SakrCommented:
hmm.. try to use the french codepage

0
 
Michel SakrCommented:
<%@ Language=VBScript Codepage=ISO-8859-1%>
0
 
marounkAuthor Commented:
Active Server Pages error 'ASP 0203'

Invalid Code Page

/magazine1/inco.asp, line 1

The specified code page attribute is invalid.
0
 
Michel SakrCommented:
When you response.write value are the french characters prserved (then no need for the code page)


try also:
value=server.HTMLEncode(value)  

before writing to the file
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.