file Protocol

Switch View :
ScriptFree
file Protocol

Opens a file on a local or network drive.

Syntax

file:///sDrives[|sFile]

Tokens

sDrives
Specifies the local or network drive.
sFile
Optional. Specifies the file to open. If sFile is omitted and the account accessing the drive has permission to browse the directory, a list of accessible files and directories is displayed.

Remarks

The file protocol and sDrives parameter can be omitted and substituted with just the command line representation of the drive letter and file location. For example, to browse the My Documents directory, the file protocol can be specified as file:///C|/My Documents/ or as C:\My Documents\. In addition, a single '\' is equivalent to specifying the root directory on the primary local drive. On most computers, this is C:\.

Available as of Microsoft Internet Explorer 3.0 or later.

Note  Internet Explorer 6  Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone. For instance, if an Internet site contains a link to a local file, Internet Explorer 6  SP1 displays a blank page when a user clicks on the link. Previous versions of Windows Internet Explorer followed the link to the local file.

Example

The following sample demonstrates four ways to use the File protocol.


//Specifying a drive and a file name. 

file:///C|/My Documents/ALetter.html

//Specifying only a drive and a path to browse the directory. 

file:///C|/My Documents/

//Specifying a drive and a directory using the command line representation of the directory location. 

C:\My Documents\

//Specifying only the directory on the local primary drive. 

\My Documents\


Community Content

David160
How do I add parameters?
Using the file protocol above, for example, file:///c|/Program Files/Microsoft Office/Office12/winword.exe will open microsoft word. How can I pass parameters or switches to word, for example, a .doc file to word for it to use; or /a ?

If I use the normal protocol, "c:\Program Files\Microsoft Office\Office12\winword.exe" /t "C:\Documents and Settings\user name\My Documents\letter.doc" then word opens letter.doc. But using the file protocol above adding /t "C:\Documents and Settings\user name\My Documents\letter.doc" generates an error message "cannot find the file". The same happens if I add /a. I know that I can address the file directly using the above file protocol, file:///C|/Documents and Settings/user name/My Documents/letter.doc will open letter.doc in word; but this will not be possible for my program, as more than one file and some switches are needed by the program. I have used word to illustrate the problem, I have another program, which I want to use the above file protocol on and uses a number of parameters and switches. What am I doing wrong?

JTip
Internet link to a local file.

"Note Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone. For instance, if an Internet site contains a link to a local file, Internet Explorer 6 SP1 displays a blank page when a user clicks on the link. Previous versions of Windows Internet Explorer followed the link to the local file."

From the note above, is there a work-around option to enable this as I have found the feature of creating secured websites that have links to my local folders or files very useful?


SacredCheese
UNC Paths
Hi Danny,

Yes, you can access UNC paths (those starting with \\servername\sharename) via the file protocol.

The syntax is file://///servername/sharename/...

Essentially this is file:/// plus the path with backslashes flipped to forward slashes.



DannyAsher
No example of using a network drive.

The text suggests this can be used for network drives that are unmapped e.g.

file:///mycomputer/public/hello.txt

but this didn't work for me. Is this possible?


yecril
URI paths are not supported
An URI containing extended characters must be UTF–8 encoded; such URIs are not supported. The workaround is to use an IRI; beware, however, that MSXML is unable to produce one. Javascript provides a function to decodeURI that you can use as a remedy.