Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert HTM page to work with ASP

Status
Not open for further replies.

AGNEW2PRG

Technical User
Aug 5, 2003
98
AE
Hi All,

I have this code that works if the page is a HTM page. I am trying to convert it to work as an asp page. The page contains the readparams() Javascript line - which I can't run in asp (I am guessing).

Is there any way I can achieve the same in asp, without having to manually enter all of the form field for every form page created?

Thanks in advance.

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Thank you for your submission</title>
</head>

<body onload="readparms()" bgcolor="#FFFFFF">

<center>
<p>&nbsp;
</p>
<h1>&nbsp;</h1>
<h1><font color="#FF0000" size="+3"><strong>Document Submitted For Print </strong></font></h1>
</center>

<script language="javascript">
function readparms()
{
writevalues(unescape(document.location.toString()));
}
</script>

<script language="vbscript">
sub writevalues(mystr)
Dim filesys, demofile, mypos, x
Set filesys = CreateObject("Scripting.FileSystemObject")
set demofile = filesys.CreateTextFile("D:\results.txt")
mystr = replace(mystr,"+"," ")
mypos = instr(mystr,"?")
for x=mypos+1 to len(mystr)
if mid(mystr,x,1)="&" then
demofile.WriteLine
else
demofile.Write mid(mystr,x,1)
end if
next
demofile.WriteLine
demofile.Close
end sub
</script>



<p align="center"><font face="Tahoma" size="2">
<a href="javascript:history.go(-1)">Back to previous page</a></font></p>



</body>
</html>
 
The page could actually be simpler in ASP. I've never user javascript to call a vbscript function, but I see that you're just calling the sub once, so I would recommend rewriting the page in ASP as follows:
Code:
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Thank you for your submission</title>
</head>

<body bgcolor="#FFFFFF">

<center>
  <p>&nbsp;</p>
  <h1>&nbsp;</h1>
  <h1><font color="#FF0000" size="+3"><strong>Document Submitted For Print </strong></font></h1>
</center>

<%
Dim filesys, demofile, mypos, x
Set filesys = CreateObject("Scripting.FileSystemObject")
set demofile = filesys.CreateTextFile("D:\results.txt")
mystr = replace(mystr,"+"," ")
mypos = instr(mystr,"?")
for x=mypos+1 to len(mystr)
   if mid(mystr,x,1)="&" then
     demofile.WriteLine
   else
     demofile.Write mid(mystr,x,1)
   end if
next
demofile.WriteLine
demofile.Close
Set filesys = Nothing
%>

<p align="center"><font face="Tahoma" size="2">
  <a href="javascript:history.go(-1)">Back to previous page</a></font></p>

</body>
</html>
 
Hi Ecwcee,

Thank You for your help. I have used the code above. Hwever, I get the following error when the page tries to create the text file.

Permission denied
/mydirectory/response.asp, line 20

The directory is under the IIS Root and I have given the IISUSER account full access. Any thoughts?

Regards
 
Permissions can be difficult. You usually need to be looking at the IUSR_ and IWAM_ accounts in order to ensure your webserver has the appropriate permissions. If the file you're trying to access is open by another user or process, or already exists at all you can also generate such errors when the webserver tries to access it for writing or deleting.
 
Apologies,

I have resolved the issue. It was permissions. however, the text file created is empty. ??
 
That's interesting. I didn't change the code inside the for loop that writes to the textfile in any way from your original listing.

Now that I look at it, the variable "mystr" is not being assigned anywhere. Sorry about that, I see it had been getting passed into the sub through the javascript call. It looks like you were using the text in the location bar as mystr, in which case you could try and assign it with:
Code:
mystr = Request.Servervariables("URL") & "?" & Request.Servervariables("QUERY_STRING")
Hopefully that helps get back to the value you had been using.
 
Do you wish to create this file on the web server machine or on the computer running the browser?
 
ecwcee - Perfect ! That worked.. Thanks very much

Sheco - I am creating the file on the server..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top