GetFileZone Method  
 

Returns the security zone information for a local file.

Syntax

object.GetFileZone( LocalFile [, HostUrl ])

Parameters

LocalFile
A string that specifies the name of a local file. This parameter must specify a regular file which exists on the local system and the current process must have permission to access and read from the file. If the file path includes environment variables surrounded in percent (%) symbols, the variables will be expanded. This parameter cannot be an empty string.
HostUrl
An optional string variable passed by referfence which will contain the URL used to originally download the file. This information is not always available, in which case an empty string will be returned. If this information is not required, this parameter may be omitted.

Return Value

An integer value which specifies the security zone for the file. It may be one of the following values:

Value Description
httpZoneNone The file does not have a zone identifier associated with it.
httpZoneLocal The file is considered to be part of the local computer zone.
httpZoneIntranet The file originates from the local intranet zone, such as an internal corporate network.
httpZoneTrusted The file originates from a site in the Trusted Sites zone.
httpZoneInternet The file was downloaded from the Internet and is treated with caution by Windows.
httpZoneRestricted The file originates from a site in the Restricted Sites zone, which is used for untrusted content.

Remarks

When a file is downloaded from the Internet or other external sources, Windows may assign a zone identifier to the file using an alternate data stream named Zone.Identifier. This metadata helps determine how the system treats the file with respect to security, such as whether to prompt the user with a warning before opening it.

The GetFileZone method retrieves the zone ID associated with the specified local file, allowing an application to determine the origin and trust level of that file. This can be useful when implementing additional security measures, auditing downloaded content, or providing user warnings about potentially untrusted files.

The file name specified by the LocalFile parameter must not reference a network location. This includes UNC paths (such as \\server\share\file.txt) and drive letters that are mapped to network shares. Security zone metadata cannot be read from files on network volumes because the SMB protocol does not support alternate data streams.

In addition to the zone ID, this method can optionally return the source URL used to download the file. This information, if present, is extracted from the same alternate data stream. Not all files will include this URL, as it depends on the program or browser that downloaded the file and whether it preserved this metadata. This method will not return an error if the URL stored with the security zone information is not a valid FTP URL. For example, it's possible for this method to return zone information with an HTTP URL. You can use the ValidateUrl method to determine if the host URL is a valid FTP URL.

Note that not all file systems support alternate data streams. For example, FAT32 volumes do not support them, and in such cases, zone information will not be available. Additionally, some applications may remove this metadata after download or strip it during file copy operations. The absence of zone information does not guarantee that a file is safe or originated locally.

If you wish to distinguish between a file which exists without any zone information, and an error condition where the file does not exist or could not be accessed, check the last error code. If this method returns httpZoneNone (-1) and the LastError property returns zero, this indicates the file name is valid and it exists, but the Zone.Identifier alternate data stream does not exist.

To manually set or remove zone information, use the SetFileZone method.

Example

The following example demonstrates how to retrieve the security zone for a local file:

Dim strHostUrl As String
Dim nZoneId As Long

nZoneId = HttpClient1.GetFileZone(strLocalFile, strHostUrl)
If nZoneId > httpZoneNone Then
    MsgBox "The file is in security zone " & nZoneId & " Url=" & strHostUrl
Else
    MsgBox "There is no security zone information for this file"
End If

See Also

ZoneId Property, GetSecurityZone Method, SetFileZone Method, ValidateUrl Method