Quantcast
Channel: Team Foundation Server - General forum
Viewing all articles
Browse latest Browse all 6687

How to connect to Team Foundation Server through client machine with C# code

$
0
0
My issue: While fetching Team project it is asking for authentication username/password again.

1. Function to pass user credentials:

public void usercredentials(String username, String password, String domain, String servername, String serverport)
{
try
{
NetworkCredential credential = new NetworkCredential(username, password);
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(tfsUri,credential);
NetworkCredential cred = new NetworkCredential(username, password, domain);
teamProjectCollection.EnsureAuthenticated();
teamProjectCollection.Authenticate();
}
catch
{
Console.WriteLine("Not able to authenticate");
}
}


2. Function to connect to TFS              
public void connectToTFS(String URI)
      {
try
{
Console.WriteLine("establishing connection to TFS . . .");
MessageBox.Show("establishing connection to TFS . . .");
Console.WriteLine("Authenticating...");

//Here we are authenticating usercredentials
usercredentials(username,password,domain,"hostname","Port");

Console.WriteLine("Authenticated...");
Console.WriteLine("connection established to TFS successfully!");
MessageBox.Show("Connection established to TFS successfully!");
}

catch (Exception e)
{
Console.WriteLine("Error in connecting to TFS " + e.Message);
}
      }


3. Fetching Team Project:

public static ProjectCollection GetAllTeamProjects()
      {
            var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tfsUri);
            var wiStore = tfs.GetService<WorkItemStore>();
            var vsStore = tfs.GetService<VersionControlServer>();
            var service = tpc.GetService<ITestManagementService>();
            var testProject = service.GetTeamProject(Name of Project);
   MessageBox.Show("All team projects collection received");
            int projCount = 0;
.....
}

If you need more information please dont feel hesitate to contact me through mail/mobile


Regards,
Vishal Deshpande
Email ID : vishal.deshpande2007@gmail.com
Phone No. +919900902883

-- Regards, Vishal D.||Sr. Test Engineer||Tech Mahindra 919900902883


Viewing all articles
Browse latest Browse all 6687

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>