0

I have a requirement to checkout and checkin file from TFS programmatically using c#. The code which I am using is as shown below.

var tfs = new TfsTeamProjectCollection(new Uri("http://MyTFSServer/"));

            var versionControlServer = tfs.GetService<VersionControlServer>();

            var workspace = versionControlServer.GetWorkspace(@"D:\Projects\");   

            var file = @"D:\Projects\Test.txt";

            workspace.PendEdit(file);

            using (StreamWriter sw = new StreamWriter(file))
            {
                sw.WriteLine("Test");
            }


            var pendingChange = workspace.GetPendingChanges();

            var changesetNumber = workspace.CheckIn(pendingChange, "checkedin the file programmatically"); 

But when I execute this code, I am getting a CheckinException - TF10141: No files checked in: resolve the conflicts and try again. in the line workspace.CheckIn(pendingChange, "checkedin the file programmatically");

How can I fix this issue?

riQQ
  • 9,878
  • 7
  • 49
  • 66
SVM
  • 15
  • 1
  • 5
  • Probably by resolving the conflict, which you'll have to do manually. – J. Steen Mar 13 '15 at 09:55
  • Thanks for the suggestion Steen. When I tried to checkin the file manually. It doesnt show any conflicts. – SVM Mar 13 '15 at 10:05
  • Is `D:\Projects` at latest when you do this? Do you want to do an explicit get latest step so that you're not editing an outdated version (and thus conflicting)? – Edward Thomson Mar 13 '15 at 11:36

1 Answers1

1

As the others have said, there is a conflict here. That can occur by pending a change on a version of the file that is not the latest and trying to check in. You can see the conflicts with QueryConflicts. You can also find a sample here.

Buck Hodges
  • 3,342
  • 1
  • 19
  • 20
  • Thanks Buck Hodges. It worked for me. As given in the sample, I created a new workspace and did a checkin and checkout. – SVM Mar 16 '15 at 06:23