Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 18th, 2003, 07:39 PM
Registered User
 
Join Date: Sep 2003
Location: SSeattle, WA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chadlupkes Send a message via Yahoo to chadlupkes
Default Text File to Array

I'm trying various ideas on how to load a text file into an array on a web page for manipulation. First question is how to load the text file into memory from a file in the same directory as the html page. The text file is basically a raw data dump from a database.

Or, if it would be simpler to use .asp to load from a database like Access, that's fine too.

I'm reading through "Beginning Javascript" by Paul Wilton, and there are lots of ideas in there about what to do with data that is manually populated in the beginning of the html page, but nothing about loading external files.

Any help would be appreciated.

Thanks!

Chad Lupkes
chadlupkes@yahoo.com
http://www.seattlewebcrafters.com
 
Old September 19th, 2003, 03:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Reading files is a bit of a no-no in JS. Its possible with the FileSystemObject, but that's Windows only and you'll need Low security settings for it to work without user prompts.

Much better to do it at the server. You can always use ASP to populate JS variables.
 
Old September 19th, 2003, 07:04 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you clarify what you are attempting? Are you tring to load a text file on the server into the client memory or the server memory, both are possible?

--

Joe
 
Old September 19th, 2003, 08:43 AM
Registered User
 
Join Date: Sep 2003
Location: SSeattle, WA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chadlupkes Send a message via Yahoo to chadlupkes
Default

Hi,

What I'm trying to do is create an application that can load a text file on the server side, then process the file based on selections from the user that they would select from options on the web page. I know this isn't an ideal situation, and that working from a database file would be much better, but I'd also like to enable file uploads from the user onto the server side so they can process their own files, as long as they are in the same format, which I would specify. Whether the processing occurs on the server side or client side isn't as important right now, I'm just trying to determine how to load the data in the file line by line so I can process it with the scripts. I know this is possible in PHP and ASP, I was just wondering if JS had something similar. I want what I create to be open source, and I'm wondering what language I should use.



Chad Lupkes
chadlupkes@yahoo.com
http://www.seattlewebcrafters.com
 
Old September 19th, 2003, 09:11 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You seem to be confusing two separate technologies, ASP and JavaScript. ASP is an architecture for running server side code in response to HTTP requests, it can be written in a number of languages, VBScript, JScript or even Perl and others if the appropriate plug-ins are installed on the server.
To open a text file on the server you can use number of techniques. The stanadard one is the FileSystemObject. This is sometimes diaallowed by anti virus sotware and also requires that the IIS account (normally IUSR_<machinename>) has read permission on the file in question.
Let's say you have uploaded a user's text file to a folder underneath the application directory called 'uploads'. If the file name is passed by to the page via a variable called 'fileName' then use code similar to this:
Code:
var ForReading = 1;
var sFileName = Request("fileName");
if (typeof sFileName == "undefined")
{
  Response.Write("Error");
  Response.End();
}
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var oTS = oFSO.OpenTextFile(Server.MapPath(sFileName), ForReading );
var sFirstLine = oTS.ReadLine();
oTS.Close();
Response.Write(sFirstLine);
Response.End();
This code runs server side so needs "<% %>" tags around it.

--

Joe




Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting text file lines into an array? georginho Visual Basic 2005 Basics 8 January 15th, 2007 09:44 AM
Function to Clear Text array! ebycorreia_81 VB How-To 1 January 16th, 2006 05:47 AM
populating an array from text box olddog VB.NET 2002/2003 Basics 1 July 27th, 2005 08:30 AM
read url file as array or text stream w_g_day Excel VBA 0 May 19th, 2005 05:49 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.