spacer
Yehuda Shiran October 19, 2000
Constructing A File Object
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

One of the less-covered subjects in JavaScript is the File IO. Usually, a JavaScript script operates on the HTML code that is already loaded onto the page, and it does not need to get more information from an external file. Like many other applications, the File IO is also based on the ActiveX technology. You create an ActiveX File object by calling ActiveXObject() with a single argument, Scripting.FileSystemObject:

myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");

You can create a File object by using the ActiveX's GetFile() method:

file = myActiveXObject.GetFile("c:\\command.com");

The File object supports various properties and methods. The following code shows how to use the name property:

alert("The name of the file is: " + file.name);

We don't show a live demo here, as for security reasons you cannot access the client file system from a server-based file.

Learn more about ActiveX controls in Column 55, OLE Automation in JavaScript.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business