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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Displaying a file on my page.

Status
Not open for further replies.

agoodrich

MIS
Jul 13, 2004
37
US
This code makes my browser sit and spin. After I load this code about 5 or six times I have to reload IIS cause it says to many users are connected. Help Please.

This code is suppose to open a file containing my table with object requests and display it on the page. This is to replace an #include that I want to make dynamic. I'm not sure where to go next.

Filename = Server.Mappath("table_template.asp")
Set fs = CreateObject("Scripting.FileSystemObject")
Set thisfile = fs.OpenTextFile(Filename, 1, False)
tempSTR = thisfile.readall
Response.Write tempSTR
thisfile.Close
Set thisfile = nothing
Set fs = nothing
 
there's size limitations to string variables, you may want to

response.write thisfile.readall

that way you wont have truncated output, as for the too many users, if you're not running IIS on a server class OS, you're limited to 10 connections.

[thumbsup2]DreX
aKa - Robert
 
Even with this basic code below the web browser hangs. I'm not sure whats happening. This is just like everyone shows for how to do this.

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
</head>
<%
varpath = Server.MapPath("test.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
Set thisfile = fs.OpenTextFile(varpath, 1)
Response.Write thisfile.readall
%>
<body>
</body>
</html>
 
before you closed out and cleared your objects, dont forget to do that.


is there a possibility that this said file might be in use otherwise? like open in notepad or something ?

[thumbsup2]DreX
aKa - Robert
 
should work, only thing i can think of is permissions/file in use

ACK *smacks forehead* you have norton antivirus on that machine? scriptblocking will prevent FSO from functioning, also alot of program installations will overwrite scrrun.dll (heart of FSO) in the system32 folder, ensure your version of that file is 5.5+

[thumbsup2]DreX
aKa - Robert
 
What would I do without you DreXor. Thanks so much. I wasted about 3 hours yesterday reading and messing around trying to get that code to work... Norton... I should have suspected it.

Its working with my little test file.. Now When I have time today I will test it out with some asp stuff.

Thanks again.
 
not a problem
glad we got it patched up :)

[thumbsup2]DreX
aKa - Robert
 
Well I kinda have what I'm after. Can anyone tell me what I'm missing. The page grabs the content of file.txt and displays it as is. It does not read it as asp code.What can I do so that it reads the file.txt as asp code. And then only displays "Hello World" on the screen?

This is my test.asp page.
==========================
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
</head>
<%
filepath = "c:\inetpub\Set fs = CreateObject("Scripting.FileSystemObject")
Set thisfile = fs.OpenTextFile(filepath, 1)
Response.Write thisfile.readall
%>
<body>
</body>
</html>
==========================

This is my file.txt contents
==========================
Response.Write "Hello World"
==========================
 
in that case you'll need to get a little more involved...

one you can take out the FSO environment and just use :

<!--#include virtual="/filefolder/test.txt"-->
OR
<!--#include File="c:\inetpub\
and it will execute it.


to use FSO and execute it ... you'll need a Execute command :)

BUT ... all the content of the grabbed file will have to be in VBS, no breaking script tags to do HTML if you have plain HTML in it everything will need to be response.write'd out.
also no <% or %> or <%=%> in the grabbed file or carried over lines, everything needs to be per line as you go.
nested conditionals get REALLY ugly this way, try to just put the code in your page.

what you have is acceptible as is, but if you add to it you'll need to watch over those conditions.

modified code for test.asp:

<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
</head>
<%
filepath = "c:\inetpub\ Set fs = CreateObject("Scripting.FileSystemObject")
Set thisfile = fs.OpenTextFile(filepath, 1)
while not thisfile.atendofstream
execute(thisfile.readline)
wend
thisfile.close
Set thisfile = nothing
Set fs = nothing
%>
<body>
</body>
</html>

[thumbsup2]DreX
aKa - Robert
 
oops
missed something in that, your script isn't between your body tags, when you response.write from the other file, it'll be before the body tag, just bad form if it goes thru.

[thumbsup2]DreX
aKa - Robert
 
I did that but the output is still

Response.Write "Hello World"

not

Hello World
 
*scratches head*

perhaps page is cached? refresh?

[thumbsup2]DreX
aKa - Robert
 
So it is possible to have asp script in the file thats being included. So it will work like using an #include only I can use it dynamicaly.
 
you cant dynamically assign a include, because those are exec'd before the asp, but you can do a block If with the include files :

[red]<!--#include virtual="<%=filename%>"-->[/red]

that will NOT work!

you have to use this type of format:
<%
If condition1 then
%>
<!--#include virtual="file1.inc"-->
<%
elseIf condition1 then
%>
<!--#include virtual="file1.inc"-->
<%
elseIf condition1 then
%>
<!--#include virtual="file1.inc"-->
<%
End If
%>

and no you cant response.Write the include either, has to break the asp code like that with the <% %> tags

[thumbsup2]DreX
aKa - Robert
 
I don't want to use includes for that reason. I don't want to use the case select option with includes either because the test.txt page will evenually be a fairly large table. That will be generated multiple times down the page depending on the number of records I load. And it wont always be the same table.

I want to do it like below... But I think i might need these <% %> so that the script contents of the file.txt is read and processed as script and not just text. I'm not sure where to put the <% %> in the code below. So right now file.txt is being written to the screen just like you see in the contents.

Once this is working I want to put it in a loop so that it displays a table with a new record each time until EOF is true. That way I'll have a page that can be printed.

This is my test.asp page.
==========================
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<%
filepath = "c:\inetpub\Set fs = CreateObject("Scripting.FileSystemObject")
Set thisfile = fs.OpenTextFile(filepath, 1)
Response.Write thisfile.readall
%>
</body>
</html>
==========================

This is my file.txt contents
==========================
Response.Write "Hello World"
==========================
 
Ok one more question on this subject cause I still don't get why it doesn't work.

In the code below why is the display for
Response.Write objrs("phone")
the correct phone number.

And the display for
Response.Write textstr
the contents of filename.txt which is
objrs("phone")

Why don't they both display the phone number on the screen?

Code:
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<%

Response.CacheControl = "no-cache"

Dim objConn
Set objConn = Server.CreateObject ("ADODB.Connection")
objConn.ConnectionString = "Driver=Microsoft Visual Foxpro Driver; SourceType=DBF; SourceDB=C:\data\phone\"
objConn.Open

Set objRS = Server.CreateObject("ADODB.Recordset")	
strSQL ="Select * from phonetable.dbf where phone = '8002334833'"
objRS.Open strSQL, objConn

filepath = "c:\inetpub\[URL unfurl="true"]wwwroot\filename.txt"[/URL]
Set fs = CreateObject("Scripting.FileSystemObject")
	Set thisfile = fs.OpenTextFile(filepath, 1)
	textstr = thisfile.readall
	
	Response.Write objrs("phone")
	
	Response.Write textstr
%>
</body>
</html>
 
are you getting phone # and the other line "response.write objrs("phone")"?



[thumbsup2]DreX
aKa - Robert
 
Yes... It would just output the contents of the file as text and not see it as asp script. However if I put an html table in the txt file then it shows up as a table and not just the code displayed on the screen.
 
HTML code written out to the text stream is just that, HTML code and is parsed by the browser.
ASP code has to be run on the server. therefore ASP code fired out in the text stream is simply seen as text.

Maybe I'm missing something here but I don't get your point of not wanting to use an include because the number of records will be different.
example: This is an include from an app I'm building. it shows related products as part of a ecommerce site. It may show 0 items or 2 or 20 or 100
the code grabs an array of data from the db using a function (GetRelatedProducts()) and displays them as links

Code:
<%
' include for displaying related products 
dim Related
dim i
Related = GetRelatedProduct(RelProdIdList)
with response
	.write "<div>" & vbCrLf
if Related(0,0) = -1 then 
	.write "<span class='brkoutheader'>" & vbCrLf
	.write "No related products"
	.write "</span>" & vbCrLf
else
	.write "<span class='brkoutheader'>" & vbCrLf
	.write ubound(Related,2) + 1
	.write " related products"
	.write "</span>" & vbCrLf
	.write "<br>" & vbCrLf
for i = 0 to ubound(Related,2)
	.write "<a class='"
	.write "designlink"
	.write "' "
	.write "href='"
	.write strShopFolder
	.write "?item="
	.write Related(0,i)
	.write "' title='"
	.write Related(1,i)
	.write "'>"  & vbCrLf
	.write Related(1,i)
	.write "</a>" & vbCrLf	
	.write "<br>"
next
end if 
	.write "</div>" & vbCrLf
end with	
%>



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top