Xander
Xander

Reputation: 9171

TFS Workspace.Get method

I am trying to do a workspace.get on a single file. However, when I call this method I am getting the entire directory and sub directories. What is the proper syntax to get the file only.

Workspace ws = _server.GetWorkspace(GetLocalPath(serverPath));
            ws.Get(new string[] { serverPath }, changesetSpec, RecursionType.Full, GetOptions.GetAll | GetOptions.Overwrite);

Upvotes: 0

Views: 571

Answers (1)

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

Check whether { serverPath } in your code below point to the specific file:

ws.Get(new string[] { serverPath }, changesetSpec, RecursionType.Full, GetOptions.GetAll | GetOptions.Overwrite);

Another way to get a specific file you can refer to this article:

string teamProjectCollectionUrl = "https://YourTfsUrl.com/tfs/YourTfsProjectCollection";

TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();

// Get the latest Item for local path "C:\projects\myfiles.cs"
Item item1 = versionControlServer.GetItem("C:\projects\myfiles.cs");

// Get ItemId = 12345 for changesetId = 54321
Item item2 = versionControlServer.GetItem(12345,54321);

// Get the latest Item for server path "$/ProjectName/myfile.cs"
Item item1 = versionControlServer.GetItem("$/ProjectName/myfile.cs", VersionSpec.Latest);

Upvotes: 1

Related Questions