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

How can I import a TXT file (output) into an html page??? 1

Status
Not open for further replies.

ahoover

Programmer
Feb 4, 2004
20
0
0
US
I have a srvinfo pulling network information on machines and dropping the output into a txt file. How can I get that data to come back to the page and be inserted into it? I can format it myself later. Please help!
 
response.write to page rather than write to the text file



Jamie Gillespie
Senior IT Technician
South Cheshire College
j-gillespie@s-cheshire.ac.uk
 
can you give me an example of a response.write command?
 
i take it we are talking web (asp) page here?

if so:
<%
response.write (MyVar)
%>



Jamie Gillespie
Senior IT Technician
South Cheshire College
j-gillespie@s-cheshire.ac.uk
 
If you want a method that works without some sort of dynamic server technology such as ASP, CGI, PHP, etc. your options are more limited. I'll assume since you posted here in VBScript you can live with an IE-only solution.

IE comes with a very handy component called the Tabular Data Control (TDC). This is meant for use with IE data binding, but you can also access the data directly from script via the TDC object's
Code:
recordset
property as well if you choose.

The idea behind TDC is for the page to fetch text file content containing tab or comma delimited text. By setting the delimiters to unlikely values and &quot;nulling out&quot; the &quot;quote&quot; or TextQualifier though, the TDC can bring back the whole text file as &quot;one row, one column&quot; - or in other words one big blob of text.

Depending on what your text file contains and how you want to display it, you might be way ahead to let it carve the file into rows or records and one or more fields. Then use data binding or the recordset to arrange for displaying it. Data binding to <TABLE>s makes some fancy stuff pretty easy though.

Hmm... just displaying the text is easy. You want to format it yourself though? A little bit more effort, not much:
Code:
<HTML>
  <HEAD>
    <TITLE>Load text via TDC</TITLE>
    <OBJECT id=objTDC
      classid=clsid:333C7BC4-460F-11D0-BC04-0080C7055A83>
      <PARAM NAME=&quot;RowDelim&quot; VALUE=&quot;&#ff;&quot;>
      <PARAM NAME=&quot;FieldDelim&quot; VALUE=&quot;&#fe;&quot;>
      <PARAM NAME=&quot;TextQualifier&quot; VALUE=&quot;&quot;>
      <PARAM NAME=&quot;DataURL&quot; VALUE=&quot;some.txt&quot;>
    </OBJECT>
    <SCRIPT language=VBScript>
      Sub btnDisplay_onclick()
        divDisplay.innerHTML = _
          Replace(divText.innerText, vbCrLf, &quot;<BR>&quot;)
      End Sub
    </SCRIPT>
  </HEAD>
  <BODY>
    <H1>All text loaded from file as one row, one column</H1>
    <DIV id=divText datasrc=#objTDC datafld=Column1
      style=&quot;display: none&quot;>
    </DIV>
    <INPUT type=button id=btnDisplay value=&quot;Display Text&quot;><BR>
    <DIV id=divDisplay>
    </DIV>
  </BODY>
</HTML>
As I said, simple.

This example uses an instance of TDC to load a file called
Code:
some.txt
from the server. You can test it locally by making some folder, creating a file
Code:
some.txt
in it. Then create a file called something like
Code:
some.htm
in this folder and paste the code above into it.

When you load this web page, the TDC will pull in the text file data as one record (row) and field (column), and using data binding will put it into the hidden <DIV> I have called
Code:
divText
. Note that since I haven't done anything fancy, the first field gets the default name
Code:
Column1
.

If you click on the button
Code:
btnDisplay
the onclick handler written in VBScript will pull the text out of
Code:
divText
, reformat it, and place it into
Code:
divDisplay.innerHTML
. In this case I didn't get fancy, I just changed all of the vbCrLf pairs into HTML line breaks.


This works from file locations, i.e. locally, or from a web server. One caveat has to do with cross-domain access: there are security features in TDC to permit or restrict that. The TDC also has to be able to &quot;see&quot; the text file: TDC needs to be able to pull the data via FILE://, FTP://, or some other URL protocol. TDC gets data the same ways that IE gets data.

You can find more on TDC at:


Sadly, further information on TDC is harder to find - though I have seen a number of MSDN articles on the subject over the years. It is one of the best reasons I ever found to say &quot;forget Netscape&quot; which doesn't offer anything remotely similar or as useful for making interactive web sites without dynamic server capabilities.

Oh yeah - TDC can't write back to the server or text file. Just thought I'd add that little bit. It is great for reporting functions though. I have even use TDC with data binding and things like the MS Chart control to provide dynamic graphical reports without needing ASP or CGI - and no steenking Java either. ;-)
 
Hello dilettante,

I find your posting answering the question with surgical precision, informative and with poignant observations. I do the easiest thing---a star.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top