Avatar of KeithMcElroy
KeithMcElroy
 asked on

Why does this use of htmlfile object not work in classic asp

doc.write htmlFile.ReadAll  causes http err 500, why?
This works in local vbscript, the fso part works ( I can response.write that part without err)
I opened up permissions.



Thanks,


Here is the html file http://pswf.net/w/test.html
Here is the url: http://pswf.net/w/w.asp
Here is the code


Dim doc, objFSO, htmlfile

Set doc = Server.CreateObject("HTMLFILE")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

set htmlFile= objFSO.OpenTextFile(Server.MapPath("test.html"))

doc.write htmlFile.ReadAll


'Response.Write doc.documentElement.outerHTML


set htmlFile = nothing
set doc = nothing
set objFSO = nothing
ASP

Avatar of undefined
Last Comment
KeithMcElroy

8/22/2022 - Mon
Big Monty

Can you make sure friendly messages are turned off in your browser so we can see the actual error message? In IE,  go to tools-> options->advanced and uncheck show friendly error messages.

Also, depending on your version of iis, you'll need to change a setting in there as well to send the errors to the browser. I believe it's under the ASP section under debugging
KeithMcElroy

ASKER
I did the second item, looking for the first
http://screencast.com/t/f5on2Vxwhwdi
Scott Fell

I tested this and it is failing at your server.createObject("HTMLFILE")

Try this instead

<%
dim sFileText
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.OpenTextFile( Server.MapPath( "test.html" ) )
sFileText = oFile.ReadAll
reponse.write sFile
oFile.Close
Set oFile = nothing
set oFSO = nothing
%>

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Scott Fell

>I did the second item, looking for the first

Keith, if you surf while logged into your server you can see the exact error.
KeithMcElroy

ASKER
I see what you mean, do it all on the server

Here is what I got

http://screencast.com/t/azYYQeu2U

Line 12 is hdoc.write htmlFile.ReadAll
KeithMcElroy

ASKER
When I response.write htmlFile.ReadAll it presents the html.
So, hdoc.write is the part that appears to not be working.  Stumped!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott Fell

I don't believe there is a doc.write in asp/vb.  You can response.write to the screen.  Or you can stream a text file to the server via fso.
Big Monty

is hdoc a typo in your last 2 posts? in your code you have the object just as doc
Big Monty

while this doesn't explain the WHY on why your page is failing, here is an alternative you may want to consider, as this will allow you to capture ANY web page:

<% 
    url = "http://www.espn.com/main.html" 
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
    xmlhttp.open "GET", url, false 
    xmlhttp.send "" 
    Response.write xmlhttp.responseText 
    set xmlhttp = nothing 
%>

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
Scott Fell

Had to double check myself.... document.write would be if you are using asp/jscript.
Scott Fell

document.write  for jscript  you have doc.write
Big Monty

scott - I believe the OP is using vbscript as defined by his first line when he is DIM-ing his variables
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
KeithMcElroy

ASKER
the htmlfile object is needed so I can traverse and manipulate the dom
I believe someone tested this on another server and it worked.
Something about this server?  This is a virtual private server hosted by jodohost.


Dim hdoc, objFSO, htmlfile

Set hdoc = Server.CreateObject("HTMLFILE")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

set htmlFile = objFSO.OpenTextFile("c:\inetpub\wwwroot\pswf_net\w\test.html")

hdoc.write htmlFile.ReadAll   <<< point of failure


'Response.Write hdoc.documentElement.outerHTML


set htmlFile = nothing
set hdoc = nothing
set objFSO = nothing
Scott Fell

That's what I thought.

What is the end result you are after.  Because the option  I gave you works.

If you want to read an xml file, you can read it just as like making a soap call and reading the response.  You can use some form of CreateObject("MSXML2.DOMDocument.3.0")

https://www.experts-exchange.com/Programming/Microsoft_Development/Q_28293687.html#a39646834
' get the response
   
dim getCustPayMethText
   getCustPayMethText=strResult
    Set objReturn = CreateObject("MSXML2.DOMDocument.3.0")
    objReturn.loadXML objXMLHTTP.responseText


' parse the response

if not objReturn.getElementsByTagName("TransactionsMatched").Item(0) is Nothing  then
	TransactionsMatched=			objReturn.getElementsByTagName("TransactionsMatched").Item(0).text
	else
	TransactionsMatched="0"
end if
if cdbl(TransactionsMatched)>0 then
for x = 0 to cint(TransactionsMatched)-1

if not objReturn.getElementsByTagName("RefNum").Item(x) is Nothing  then
	RefNum=			objReturn.getElementsByTagName("RefNum").Item(x).text
	else
	RefNum="N/A"
end if

if not objReturn.getElementsByTagName("Result").Item(x) is Nothing  then
	Result=			objReturn.getElementsByTagName("Result").Item(x).text
	else
	Result="N/A"
end if

if not objReturn.getElementsByTagName("ResultCode").Item(x) is Nothing  then
	ResultCode=			objReturn.getElementsByTagName("ResultCode").Item(x).text
	else
	ResultCode="N/A"
end if

if not objReturn.getElementsByTagName("CardNumber").Item(x) is Nothing  then
	CardNumber=			objReturn.getElementsByTagName("CardNumber").Item(x).text
	else
	CardNumber="NA/A"
end if

if not objReturn.getElementsByTagName("TransactionType").Item(x) is Nothing  then
	TransactionType=			objReturn.getElementsByTagName("TransactionType").Item(x).text
	else
	TransactionType="0"
end if

searchTransactions="TransactionsMatched,"&"RefNum,"&"Result,"&"ResultCode,"&"CardNumber,"&"TransactionType"&

end Function
                         

Open in new window

Big Monty

looks like it IS the server, I just ran a quick test on my site and it worked:

http://www.exchangetree.org/test.asp

pulling data from http://www.exchangetree.org/test.htm

my code is the same except I uncommented the line right after the hdoc.write
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Scott Fell

I meant, this option works http:Q_28439525.html#a40083287  and so does xmlhttp post that Big Monty gave you.

I think you have an answer between all of this, it is just not the same as what you did on the other server.  They probably had a component installed that you no longer have.
KeithMcElroy

ASKER
Yes, it is the server, not sure what.  Other com objects such as fso work.
Any ideas on configs in IIS that would cause this?
Big Monty

I don't think there's anything in IIS that would fix this, it's either a permissions issue or the DLL needs to be re-registered. Unfortunately I don't know what DLL controls that com object.

I have to jump offline for a bit, will check back in later.

good luck!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
KeithMcElroy

ASKER
Tried this using the msxml object for retrieving the html.  Same result.
It works in vb script running locally in a .vbs file
I need the htmlfile object because of its html dom based features


Dim html, http

set html = Server.CreateObject("htmlfile")

Set http = Server.CreateObject("MSXML2.XMLHTTP")

http.open "POST", Server.MapPath("test.html"), False
http.send

response.write http.responseText
html.write http.responseText


set html = nothing
set http = nothing
Scott Fell

What is it you are trying to extract from this?  

I have used the xmlhttp post that big monty showed you to grab a page, remove some classes and add some others based on the html pattern and scrap only the portion I needed to display on a website. This was for a team site that had permission to grab some data from a league site for standings.  I know it can be done.

<!DOCTYPE html>
<html>
<head>
</script>
</head>
<body>

Test Content

</body>
</html>

Open in new window

Scott Fell

This http:Q_28439525.html#a40083287 is doing I think exactly what you are trying to do here http:#a40083611
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Scott Fell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
KeithMcElroy

ASKER
I tested on another server.  It works out of the box.  This is two servers now that work fine.
The issue is obviously something quirky with the virtual server.
I think my next step is to approach the hosting company, jodohost, and have them try it on another one of their servers.

I feel like I gained what I needed to solve this problem.  I have enough to at least go to the hosting company.
Awarding points.  I hope this is acceptable.


Thanks a bunch!
KeithMcElroy

ASKER
Great help with a very challenging problem!
Scott Fell

I think it is part of being a classic asp dev.   I always fee like every server is completely different and only 90% of what I have on one server will work on the next.      I have been making the switch to PHP.  At least there it is a matter of which version is installed and based on that you know exactly what you have.

Best of luck!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Big Monty

none of my answers helped you out at all? bummer!

figured it would have bee n a split since I confirmed that the code was correct as well on my own server, and suggested that it was a server configuration issue as well.

oh well, glad you have a game plan going forward
KeithMcElroy

ASKER
I should have done it that way. :-(