Returns the UNC path for a file or directory in a FileTable.
Applies to: SQL Server (SQL Server 2012 through current version).
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.
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’;