Retrieving Files from TFS programatically


This article explain about how to Retrieving Files from TFS pragmatically

I have created an application for my own purpose, that will retrieve all the files from TFS programatically. Code for files retrieval have been given here.


using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Common;
using Microsoft.TeamFoundation.VersionControl.Client;
....
TeamFoundationServer tfs = new TeamFoundationServer("http://TFSServer:Port/", new System.Net.NetworkCredential("sUserName", "sPassword"));
tfs.EnsureAuthenticated();

Workspace workspace = null;
try
{
// Connect to TFS Source Control
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

// Create a Workspace
string repository = txtWorkspace;

// location to check out files to:
string workspacePath = @"" + "Folder";

workspace = vcs.CreateWorkspace("TestWorkSpace", vcs.AuthenticatedUser);
WorkingFolder folder = new WorkingFolder(repository, workspacePath);

// Get Files
workspace.CreateMapping(folder);
workspace.Get();
}
catch(Exception ex)
{
//Exception has to be handled here
}
finally
{
// clean up the workspace for subsequent passes.
if (workspace != null)
workspace.Delete();
}


Comments

Guest Author: ram salunke06 Aug 2012

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Common;
using Microsoft.TeamFoundation.VersionControl.Client;

How to add this name spaces in our .cs file

Guest Author: ram salunke06 Aug 2012

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Common;
using Microsoft.TeamFoundation.VersionControl.Client;

how to add this namespaces in our.cs file



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: