World Library  
Flag as Inappropriate
Email this Article

File URI scheme

Article Id: WHEBN0014559427
Reproduction Date:

Title: File URI scheme  
Author: World Heritage Encyclopedia
Language: English
Subject: Uniform Resource Identifier, Uniform resource locator, Distributed Social Networking Protocol, Run command, Webcal
Collection: Identifiers, Internet Standards, Uri Schemes
Publisher: World Heritage Encyclopedia

File URI scheme

The file URI scheme is a URI scheme specified in RFC 1630 and RFC 1738, typically used to retrieve files from within one's own computer.


  • Format 1
  • Meaning of slash character 2
  • Examples 3
    • Unix 3.1
    • Windows 3.2
  • Things to consider 4
    • Windows 4.1
    • Legacy URLs 4.2
    • Web pages 4.3
  • References 5
  • External links 6


A file URI takes the form of


where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name. If host is omitted, it is taken to be "localhost", the machine from which the URL is being interpreted. Note that when omitting host, the slash is not omitted ("file:///foo.txt" is valid, while "file://foo.txt" is not, although some interpreters manage to handle the latter).

Meaning of slash character

The slash character (/), depending on its position, has different meanings within a file URL.

  • The // after the file: is part of the general syntax of URLs. (The double slash // should always appear in a file URL according to the specification, but in practice many Web browsers allow it to be omitted).
  • The single slash between host and path is part of the syntax of URLs.
  • The slashes in path separate directory names in a hierarchical system of directories and subdirectories. In this usage, the slash is a general, system-independent way of separating the parts, and in a particular host system it might be used as such in any pathname (as in Unix systems).



Here are two Unix examples pointing to the same /etc/fstab file:



Here are some examples which may be accepted by some applications on Windows systems, referring to the same, local file c:\WINDOWS\clock.avi


Here is the URI as understood by the Windows Shell API:[1]


Things to consider


On Microsoft Windows systems, the normal colon (:) after a device letter has sometimes been replaced by a vertical bar (|) in file URLs. This reflected the original URL syntax, which made the colon a reserved character in a path part.

Since Internet Explorer 4, file URIs have been standardized on Windows, and should follow the following scheme. This applies to all applications which use URLMON or SHLWAPI for parsing, fetching or binding to URIs. To convert a path to a URL, use UrlCreateFromPath, and to convert a URL to a path, use PathCreateFromUrl. [2]

To access a file "the file.txt", the following might be used.

For a network location:


Or for a local file, the hostname is omitted, but the slash is not (note the third slash):


This is not the same as providing the string "localhost" or the dot "." in place of the hostname. The string "localhost" will attempt to access the file as \\localhost\c:\path\to\the file.txt, which will not work since the colon is not allowed in a share name. The dot "." results in the string being passed as \\.\c:\path\to\the file.txt, which will work for local files, but not shares on the local system. For example file://./sharename/path/to/the%20file.txt will not work, because it will result in sharename being interpreted as part of the DOSDEVICES namespace, not as a network share.

The following outline roughly describes the requirements.

  • The colon should be used, and should not be replaced with a vertical bar for Internet Explorer.
  • Forward slashes should be used to delimit paths. note that while DOS requires backslashes, the Win32 API will accept either a forward or back slash.
  • Characters such as the hash (#) or question mark (?) which are part of the filename should be percent-encoded.
  • Characters which are not allowed in URIs, but which are allowed in filenames, must also be percent-encoded. For example, any of "{}`^ " and all control characters. In the example above, the space in the filename is encoded as %20.
  • Characters which are allowed in both URIs and filenames must NOT be percent-encoded.
  • Must not use legacy ACP encodings. (ACP code pages are specified by DOS CHCP or Windows Control Panel language setting.)
  • Unicode characters outside of the ASCII range must be UTF-8 encoded, and those UTF-8 encodings must be percent-encoded.

Use the provided functions if possible. If must create a URL programmatically and cannot access SHLWAPI.dll (for example from script, or another programming environment where the equivalent functions are not available) the above outline will help.

Legacy URLs

To aid the installed base of legacy applications, the PathCreateFromUrl recognizes certain URLs which do not meet these criteria, and treats them uniformly. These are called "legacy" file URLs as opposed to "healthy" file URLs. [3]

In the past, a variety of other applications have used other systems. Some added an additional two slashes. For example, \\remotehost\share\dir\file.txt, would become file:////remotehost/share/dir/file.txt instead of the "healthy" file://remotehost/share/dir/file.txt.

Web pages

File URLs are rarely used in Web pages on the Internet, since they make the assumption that such a file exists on the client's computer. The host specifier can be used to retrieve a file from an external source, although no specific file-retrieval protocol is specified; and using it should result in a message that informs the user that no mechanism to access that machine is available.


  1. ^ Risney, Dave (2006). "File URIs in Windows". IEBlog. Microsoft Corporation. Retrieved 31 July 2013. 
  2. ^ File URIs in Windows - IEBlog - Site Home - MSDN Blogs. (2006-12-06). Retrieved on 2014-03-08.
  3. ^ The Bizarre and Unhappy Story of 'file:' URLs - Free Associations - Site Home - MSDN Blogs. (2005-05-19). Retrieved on 2014-03-08.

External links

  • File URLs
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.