Export (0) Print
Expand All

GetFileNamespacePath (Transact-SQL)

Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Returns the UNC path for a file or directory in a FileTable.

Applies to: SQL Server (SQL Server 2012 through current version).

<column-name>.GetFileNamespacePath(is_full_path, @option)


The column name of the VARBINARY(MAX) file_stream column in a FileTable.

The column-name value must be a valid column name. It cannot be an expression, or a value converted or cast from a column of another data type.


An integer expression that specifies whether to return a relative or an absolute path. is_full_path can have one of the following values:




Returns the relative path within the database-level directory.

This is the default value


Returns the full UNC path, starting with the \\computer_name.


An integer expression that defines how the server component of the path should be formatted. @option can have one of the following values:




Returns the server name converted to NetBIOS format, for example:


This is the default value.


Returns the server name without conversion, for example:



Returns the complete server path, for example:



If the SQL Server instance is clustered in a failover cluster, then the machine name that is returned as part of this path is the virtual hostname for the clustered instance.

When the database belongs to an AlwaysOn availability group, then the FileTableRootPath function returns the virtual network name (VNN) instead of the computer name.

The path that the GetFileNamespacePath function returns is a logical directory or file path in the following format:

\\<machine>\<instance-level FILESTREAM share>\<database-level directory>\<FileTable directory>\...

This logical path does not directly correspond to a physical NTFS path. It is translated to the physical path by FILESTREAM’s file system filter driver and the FILESTREAM agent. This separation between the logical path and physical path lets SQL Server reorganize data internally without affecting the validity of the path.

To keep code and applications independent of the current computer and database, avoid writing code that relies on absolute file paths. Instead, get the complete path for a file at run time by using the FileTableRootPath and GetFileNamespacePath functions together, as shown in the following example. By default, the GetFileNamespacePath function returns the relative path of the file under the root path for the database.

USE MyDocumentDB;
@root varchar(100)
SELECT @root = FileTableRootPath();

@fullPath = varchar(1000);
SELECT @fullPath = @root + file_stream.GetFileNamespacePath() FROM DocumentStore
WHERE Name = N’document.docx’;

The following examples show how to call the GetFileNamespacePath function to get the UNC path for a file or directory in a FileTable.

-- returns the relative path of the form “\MyFileTable\MyDocDirectory\document.docx”
SELECT file_stream.GetFileNamespacePath() AS FilePath FROM DocumentStore
WHERE Name = N’document.docx’;

-- returns “\\MyServer\MSSQLSERVER\MyDocumentDB\MyFileTable\MyDocDirectory\document.docx”
SELECT file_stream.GetFileNamespacePath(1, Null) AS FilePath FROM DocumentStore
WHERE Name = N’document.docx’;
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft