Anand Kumar
Anand Kumar

Reputation: 425

C# TFS API "There is no working folder C:\TFS' in VS2008 installed system

I want to find out the files recently checked in using C# and TFS API from TFS2010. It works fine where MS Visual studio 2010 is installed. this is developed using VS2010, .Net 3.5.

When I use this exe in system having VS2008 installed throws error as "*There is no working folder C:\TFS"*.

any suggestion please. is there any way to get result from TFS without considering local mappings?

TeamFoundationServer tfsServer = new TeamFoundationServer("http://snchndevtfsapp:8080/tfs/defaultcollection");
WorkItemStore workItemStore = new WorkItemStore(tfsServer);
VersionControlServer vcServer = tfsServer.GetService(typeof(VersionControlServer)) as VersionControlServer;
var usersWorkspaces = vcServer.QueryWorkspaces(null, vcServer.AuthorizedUser, Environment.MachineName).ToList();

List<ChangedTFSItem> foundPastChanges = new System.Collections.Generic.List<ChangedTFSItem>();

var allPastChangesets = vcServer.QueryHistory(@"C:\TFS",
                                              VersionSpec.Latest,
                                              0,
                                              RecursionType.Full,
                                              null,
                                              null,
                                              null,
                                              1000,
                                              true,
                                              false).Cast<Changeset>();
//.Where(x => x.Committer.Contains(Environment.UserName));


List<ChangedTFSItem>  _foundPastChanges = allPastChangesets
    .SelectMany(x => x.Changes)
    .Where(x => x.Item.CheckinDate.Date >= ((DateTime)dateEdit1.EditValue))
    //.DistinctBy(x => x.Item.ServerItem, x => x.Item.ServerItem.GetHashCode())
    .Select(x => new ChangedTFSItem()
        {
            FileName = Path.GetFileName(x.Item.ServerItem),
            ServerItem = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem).Replace(textEdit1.Text, ""),
            LocalPath = usersWorkspaces[0].GetLocalItemForServerItem(x.Item.ServerItem),
            ChangeTypeName = x.ChangeType.ToString(),
            ChangeDate = x.Item.CheckinDate.ToString()
        }).ToList();

Upvotes: 3

Views: 2806

Answers (1)

pantelif
pantelif

Reputation: 8544

Instead of placing a physical path as your first argument in Query History @"C:\TFS", try using a source control path. If are interested in all changesets, simply place the root "$/".

For the task you are trying to accomplish, you can skip any local workspace connection by doing something like this:

using System;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace GetFilesOfLatestChangesets
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("TFS_URI"));
            var vcS = teamProjectCollection.GetService(typeof (VersionControlServer)) as VersionControlServer;
            var changesets =
                vcS.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 10, true, false).
                    Cast<Changeset>();
            foreach (var changeset in changesets)
            {
                Console.WriteLine("Changes for "+changeset.ChangesetId);
                foreach (var change in changeset.Changes)
                {
                   Console.WriteLine(change.Item.ServerItem); 
                }
            }  
        }
    }
}

but then you 'll retrieve the server paths for the changed modules and not where they have been mapped in your workstation.

One final remark: You have to QueryHistory with includeChanges = true, therefore asking for the last 1000 changesets should be rather expensive.

Upvotes: 4

Related Questions