Link to home
Start Free TrialLog in
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
Avatar of Big Monty
Big Monty
Flag of United States of America image

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
Avatar of KeithMcElroy
KeithMcElroy

ASKER

I did the second item, looking for the first
http://screencast.com/t/f5on2Vxwhwdi
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

>I did the second item, looking for the first

Keith, if you surf while logged into your server you can see the exact error.
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
When I response.write htmlFile.ReadAll it presents the html.
So, hdoc.write is the part that appears to not be working.  Stumped!
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.
is hdoc a typo in your last 2 posts? in your code you have the object just as doc
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

Had to double check myself.... document.write would be if you are using asp/jscript.
document.write  for jscript  you have doc.write
scott - I believe the OP is using vbscript as defined by his first line when he is DIM-ing his variables
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
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/questions/28293687/Classic-ASP-and-SOAP.html?anchorAnswerId=39646834#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

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
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.
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?
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!
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
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

This http:Q_28439525.html#a40083287 is doing I think exactly what you are trying to do here http:#a40083611
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
Great help with a very challenging problem!
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!
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
I should have done it that way. :-(