Solved

FileSystemObject

Posted on 2001-06-26
32
349 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:marounk
  • 16
  • 8
  • 3
  • +3
32 Comments
 
LVL 20

Expert Comment

by:jitganguly
ID: 6227793
Use writeline

objTStream.WriteLine value
 
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6227896
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6227907
2cents: If nothing works try to write to the stream by chunks..
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6227924
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6227929
>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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6227932
>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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6227943
The IUSR_Webservername is the one that you should grant full permissions to the file, if anonymous account is enabled..
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6228046
try:

Call objTStream.Write(value)

or

objTStream.Write value
0
 
LVL 2

Expert Comment

by:preinsko
ID: 6229807
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
 
LVL 14

Expert Comment

by:puranik_p
ID: 6229990
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
 
LVL 1

Author Comment

by:marounk
ID: 6230119
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 6230123
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
 
LVL 1

Author Comment

by:marounk
ID: 6230135
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 6230151
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230179
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230183
errata:
valueX = right(value,ZLength - (ZLength MOD 3000)

should have a closing parantheses and like this

valueX = right(value,(ZLength MOD 3000))
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:preinsko
ID: 6230217
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
 
LVL 1

Author Comment

by:marounk
ID: 6230222
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
 
LVL 1

Author Comment

by:marounk
ID: 6230233
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230262
maroun, I posted you a code on how to do it.. you can add it in a function for repeated reusability..

rgrds
0
 
LVL 1

Author Comment

by:marounk
ID: 6230290
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230293
or is it Tarek ;o)
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230304
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
 
LVL 1

Author Comment

by:marounk
ID: 6230373
fails too ~!!! this problem is driving me nuts ~~
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230392
what's the error now?
0
 
LVL 1

Author Comment

by:marounk
ID: 6230393
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
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230396
can you post the url you're fetching? or email it to silvers@rocketmail.com(if it's on the web)
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230410
hmm.. try to use the french codepage

0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230448
<%@ Language=VBScript Codepage=ISO-8859-1%>
0
 
LVL 1

Author Comment

by:marounk
ID: 6230480
Active Server Pages error 'ASP 0203'

Invalid Code Page

/magazine1/inco.asp, line 1

The specified code page attribute is invalid.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6230495
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
 
LVL 20

Accepted Solution

by:
Silvers5 earned 50 total points
ID: 6230511
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now