Show / Hide Table of Contents

# Class Workspace

Manages a "workspace" of script files that are open for a particular editing session. Also helps to navigate references between ScriptFiles.

##### Inheritance

System.Object
Workspace

##### Inherited Members

System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()

###### Namespace:Microsoft.SqlTools.ServiceLayer.Workspace

###### Assembly:Microsoft.SqlTools.ServiceLayer.dll

##### Syntax

    public class Workspace : IDisposable

### Constructors

| Improve this Doc View Source

#### Workspace()

Creates a new instance of the Workspace class.

##### Declaration

    public Workspace()

### Properties

| Improve this Doc View Source

#### WorkspacePath

Gets or sets the root path of the workspace.

##### Declaration

    public string WorkspacePath { get; set; }

##### Property Value

Type | Description
--- | ---
System.String |

### Methods

| Improve this Doc View Source

#### CloseFile(ScriptFile)

Closes a currently open script file with the given file path.

##### Declaration

    public void CloseFile(ScriptFile scriptFile)

##### Parameters

Type | Name | Description
--- | --- | ---
ScriptFile | scriptFile | The file path at which the script resides.

| Improve this Doc View Source

#### Dispose()

Disposes of any Runspaces that were created for the services used in this session.

##### Declaration

    public void Dispose()

##### Implements

System.IDisposable.Dispose()
| Improve this Doc View Source

#### GetFile(String)

Gets an open file in the workspace. If the file isn't open but exists on the filesystem, load and return it. Virtual method to allow for mocking

##### Declaration

    public virtual ScriptFile GetFile(string filePath)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | filePath | The file path at which the script resides.

##### Returns

Type | Description
--- | ---
ScriptFile |

##### Exceptions

Type | Condition
--- | ---
System.IO.FileNotFoundException | filePath is not found.
System.ArgumentException | filePath contains a null or empty string.

| Improve this Doc View Source

#### GetFileBuffer(String, String)

Gets a new ScriptFile instance which is identified by the given file path and initially contains the given buffer contents.

##### Declaration

    public ScriptFile GetFileBuffer(string filePath, string initialBuffer)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | filePath |
System.String | initialBuffer |

##### Returns

Type | Description
--- | ---
ScriptFile |

| Improve this Doc View Source

#### GetOpenedFiles()

Gets an array of all opened ScriptFiles in the workspace.

##### Declaration

    public ScriptFile[] GetOpenedFiles()

##### Returns

Type | Description
--- | ---
ScriptFile[] | An array of all opened ScriptFiles in the workspace.

| Improve this Doc View Source

#### UnescapePath(String)

Unescapes any escaped [, ] or space characters. Typically use this before calling a .NET API that doesn't understand PowerShell escaped chars.

##### Declaration

    public static string UnescapePath(string path)

##### Parameters

Type | Name | Description
--- | --- | ---
System.String | path | The path to unescape.

##### Returns

Type | Description
--- | ---
System.String | The path with the ` character before [, ] and spaces removed.