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!

Read a text file

Status
Not open for further replies.

rondavid

Programmer
Apr 29, 2003
19
US
Ok can someone tell me how I can load a text file residing on the server using client VBScript from web page. The OpenTextFile opens a text file on your local drive. I would greatly appreciate the help.
 
There are several methods that can be used to accomplish this in Internet Explorer. A lot depends on what the format of your data is and what you want to do with it.

The XMLHTTP object (part of MSXML) is usable for non-XML data as well as XML data. This requires IE 5.0 and later though I'm pretty sure.

The TDC (Tabular Data Control) was included with IE starting at about 4.0 I think.

XMLHTTP can be used to grab a blob of data from the server for you, but it won't know much about breaking up lines or records. You'll get the whole thing as one string.

TDC was intended for CSV text files. The main use of TDC is IE data-bound elements such as tables, but it exposes a recordset property that is almost identical to an ADO recordset in most respects. You can also "fool" TDC into loading a while text file as one string something like XMLHTTP will do.

There are a couple of other things from Microsoft that will work but are discouraged on the client side.

Microsoft also offered a Java applet at one time that made it possible to write a DHTML page that ran on any browser that supported Java applets and Javascript. This is pretty dead now though.
 
Thanks but I'm a little confused. So you're saying that I would have to use the Tabular Data Control. What is that and where could I find it. I'm kind of new to this stuff. Couldnt I just use some kind of FTP command to read the file and write to it from the browser. I looked up something called FTPOpenFile but wasn't sure how its used.
 
TDC can only read from the web server. So maybe that won't fit the bill.

XMLHTTP can read and write back, but the write back is a POST so you'll need something to accept the data... like an ASP page.

I'm not sure what FTPOpenFile refers to, but there are components that'll run client-side that can do FTP. Of course you'll need FTP access to the server then too as well as HTTP.

I think XMLHTTP is capable of a WebDAV PUT as well, but this takes us into even deeper territory.

What are you trying to accomplish? Maybe more information will get you a better answer.
 
Here's what I have. It's an events page and they want to be able to modify the contents of the page from the page so they can update the events. So what I did was create a table that has 10 rows and 2 columns. Each row contains a text field and a textarea field. The text field for the event date and the textarea field for a description. On Window Load I open a text file read the contents and assign the values to the text fields and then make them read only. When the user hits a hot spot on the page I make all the text fields enabled so the user can change the data within them. I also make a hidden button visible. When they click the button, I read the values from the text fields and write them back to the text file, make all the text fields read only again and hide the button. The only problem I'm having is that I the text file has to be on the server so that the web world can view the updated changes. The worst part is that I'm new to this stuff.
 
Well, this sounds like basic ASP stuff.

People usually don't try to get so fancy client-side. More typically you'd use a form and just have the submit action post the results back to the server. This is more of an ASP issue and you might try posting in the ASP forum. I'd start by reading up on ASP first though, this is really basic stuff and sort of clumsy to cover in here.

There are lots of other solutions (PHP, etc.) that amount to the same thing. All depends on what server-side technologies you have at your disposal.

Sorry to send you down a blind alley. Things like FSO aren't normally used in web applications. And TDC/data-binding and MSXML are more advanced topics.
 
Thank you very much for your help. You're absolutely right it's an asp thing. I finally figured it out obviously using ASP. Sorry about wasting your time, like I said I'm kind of new to this thing. But learn quickly. Thanks again for all the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top