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

open file from web server

Status
Not open for further replies.

DGoulston

Technical User
Jun 17, 2002
21
GB
ok i have the code below open a file, but it opens a file from the computer the page is accessed from and not a file from where the html doc exists. and if i try take away the c:\ then it cant find the file at all...
(this is only a section of the code, i do a lot of work with the file. which all works fine)

Code:
<html>
<head>
<script language=&quot;vbscript&quot;>
  Option Explicit
  Sub tstvb()
	dim filesys, readfile
	set filesys = CreateObject(&quot;Scripting.FileSystemObject&quot;)
	set readfile = filesys.OpenTextFile(&quot;c:\auth.txt&quot;, 1, false)
 end sub
</script>
</head>
<body>
<script language=&quot;vbscript&quot;>
       call tstvb()
 </script>

<br><br>
</body>
</html>

thanks in advanced..

Regards
Dal

##########################
# #
# Darren@DGoulston.com #
##########################
 
You are running a client-side script.
To make it a server-side script, put your VBScript inside <% and %>

and use Server.CreateObject instead of CreateObject

<%
Option Explicit
Sub tstvb()
dim filesys, readfile
set filesys = CreateObject(&quot;Scripting.FileSystemObject&quot;)
set readfile = filesys.OpenTextFile(&quot;c:\auth.txt&quot;, 1, false)
end sub
%>
 
i am not using asp... i am using vbscript because i am purposly only using a simplistic web server that does not support much, everything is working fine so far, im reading in a file, cuting it up, putting it into arrays, displayin parts, but currently it comes from the client computer and i want it to come from the host...

regards
Darren.

(i tried changing it to <% and got the error
expected ;
and on the screen it displays:

&quot;)document.write(&quot;
&quot;)document.write(&quot;
&quot;)//if rec count

etc....

####################
# #
# Darren@DGoulston.com #
###################
 
the vbscript you wrote is client-side script, it will process only files on client's PC. If you want to open files on server, you must use server-side script. VBScript in HTML file will only run on client's PC.

 
If in an intranet, you can try to use UNC name or mapped drive.

Hope This Help
PH.
 
but server side is asp is it not? <% & %> makes it asp dont it?? the server im using only supports VBScript enless anyone knows a FREE asp standalone server (not the one provided with windows) becasue i need to re-distribute it.

regards
Dal

####################
# #
# Darren@DGoulston.com #
###################
 
besides adding <% and %> you need an asp interpreter (like IIS, Chili!Soft ASP, ... I think you don't have it so you got error after adding <% and %>. Sorry, I don't know any free asp server to re-distribute.
 
Hello DGoulston and all,

I see a lot of contradictory assertions in DGoulston's postings. So I do not know how sophisticated his skill is. Going into detail may have some code line seems urgly, but that is how script works. You see it and you know it. That is the best way to help the perplexed.
Code:
<!-- .htm, client side, auth.txt in same folder as the .htm -->
<html>
<head>
<script language=&quot;vbscript&quot;>
  Option Explicit
  Sub tstvb()
    dim filesys, readfile
    set filesys = CreateObject(&quot;Scripting.FileSystemObject&quot;)
	dim sPath, sFile
	sPath = window.location.href
	sPath=Mid(sPath, instr(sPath,&quot;///&quot;)+3, instrrev(sPath,&quot;/&quot;)-instr(sPath,&quot;///&quot;)-3)
	sFile = sPath &&quot;/&quot;& &quot;auth.txt&quot;
	set readfile = filesys.OpenTextFile(sFile, 1, false)
	dim text, textwithcrlf
	text = readfile.readall
        readfile.close
	textwithcrlf = &quot;&quot;
	set readfile = filesys.OpenTextFile(sFile, 1, false)
	Do while Not readfile.AtEndOfStream
		textwithcrlf = textwithcrlf & readfile.readline & &quot;<br>&quot;
	Loop
    	readfile.close
	set readfile = nothing
	set filesys = nothing
	document.write text & &quot;<br>&quot;
	document.write textwithcrlf
 end sub
</script>
</head>
<body>
<script language=&quot;vbscript&quot;>
       call tstvb()
</script>
<br><br>
</body>
</html>
Now, an asp version whatever you take it as.
Code:
<!-- .asp server-side, auth.txt in the same folder as the .asp -->
<%@ language=&quot;vbscript&quot; %>
<html>
<head>
<script language=&quot;vbscript&quot;>
<%
  Option Explicit
  Sub tstvb()
    dim filesys, readfile
    set filesys = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
	dim sPath, sFile
	sPath = Server.MapPath(&quot;.&quot;)
	sFile = sPath &&quot;\&quot;& &quot;auth.txt&quot;
	set readfile = filesys.OpenTextFile(sFile, 1, false)
	dim text, textwithcrlf
	text = readfile.readall
        readfile.close
	textwithcrlf=&quot;&quot;
	set readfile = filesys.OpenTextFile(sFile, 1, false)
	Do While Not readfile.AtEndOfStream
		textwithcrlf=textwithcrlf & readfile.readline & &quot;<br>&quot;
	Loop
    	readfile.close
	set readfile = nothing
	set filesys = nothing
	response.write text & &quot;<br>&quot;
	response.write textwithcrlf & &quot;<br>&quot;
 end sub
%>
</script>
</head>
<body>
<script runat=Server language=&quot;vbscript&quot;>
       call tstvb()
</script>
<br><br>
</body>
</html>
regards - tsuji
 
your first piece of code looked good but the output of the path is: tp://10.0.11.29/auth.txt (which is the address of the file but what is the tp?

anyway not to worry as i am hard coding it in the server and going to be using [d--fieldname--d] to suplement anything i need to display in the html doc and have it do it in c++ before it is sent to the browser.

thanks for all your help

Darren

####################
# #
# Darren@DGoulston.com #
###################
 
Hello DGoulston,

My original demonstration script you referred to is for &quot;client-side&quot; for sure and more it is for a local m/c with drives mapped or local. If you use ip address to reach a remote m/c on a intranet or something, you have to change the parsing lines (which I referred to as urgly). &quot;tp&quot; is truncated out of &quot;http&quot;. It has no universal significance. It only means those lines will not be applicable to your config. As only you the configuration of the network, you have just to design your own parsing routine to make it work. That's all.

regards - tsuji
 
yes i have to agree that accessing that accessing the file through the ip address is not nice, all i wanted was some VBScript code that read the file from the httpsrv server. as i said i am hardcoding the file handeling into the server using c++ and it works fine, thanks for all you guys help

Regards
Dal

####################
# #
# Darren@DGoulston.com #
###################
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top