diff --git a/src/Microsoft.SqlTools.ServiceLayer/FileBrowser/FileBrowserOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/FileBrowser/FileBrowserOperation.cs index a744b37e..9183e14c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/FileBrowser/FileBrowserOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/FileBrowser/FileBrowserOperation.cs @@ -160,7 +160,19 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser { this.fileTree.SelectedNode = lastNode; } - throw new FileBrowserException(string.Format(SR.InvalidPathError, this.expandPath)); + + // If root folders returned from sys.dm_os_enumerate_filesystem don't match the folders present, expandPath might not be found + // Bug: https://github.com/microsoft/azuredatastudio/issues/4767 + // Workaround : scope file browser tree to expandPath explicitly + try + { + this.ScopeFileTreeToPath(expandPath); + return; + } + catch + { + throw new FileBrowserException(string.Format(SR.InvalidPathError, this.expandPath)); + } } } @@ -204,7 +216,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser } public List GetChildren(string filePath) - { + { List children = new List(); foreach (var file in EnumerateFilesInFolder(Enumerator, connection, filePath)) { @@ -248,6 +260,26 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser return false; } + /// + /// Creates file tree for a scoped path + /// Removes the top level file tree so only use this if you intend to do that + /// + /// path to consider at top level node for tree + private void ScopeFileTreeToPath(string expandPath) + { + this.fileTree = new FileTree(); + FileTreeNode node = new FileTreeNode() + { + Name = expandPath, + FullPath = expandPath, + IsExpanded = true + }; + + this.fileTree.RootNode.AddChildNode(node); + node.Children = this.GetChildren(node.FullPath); + this.fileTree.SelectedNode = node; + } + /// /// Compares a file name to the user specified mask using a regular expression ///