How to delete a file ( eg: test.cs ) from TFS source repository programmatically using TFS API


  • Hi all,

    I'm looking for a way to delete a csharp file from TFS source repository using TFS API., here is the pseudo code that i follwed but it's not working

                                          // delete unit test file from the TFS source code repository
                                            Workspace workspace = null;
                                            workspace = CreateWorkSpace(); // my own function to create the workspace
                                            if (workspace != null)
                                                string unittestfile = "UnitTest111.cs";
                                                string unittestfilePath = Path.Combine(CTFSConfig.WorkspacePath, CTFSConfig.CSProjectFolder, unittestfile);
                                                // to remove the ReadOnly attribute
                                                var projectattributes = File.GetAttributes(unittestfilePath);
                                                projectattributes = projectattributes & ~FileAttributes.ReadOnly;
                                                File.SetAttributes(unittestfilePath, projectattributes);
                                                int ret = workspace.PendDelete(unittestfilePath);  // delete the file
                                                PendingChange[] pendingChanges = workspace.GetPendingChanges();
                                                workspace.CheckIn(pendingChanges, "Unit test file deleted programatically");

    Please suggest me the correct way of doing.


    • Moved by niveditabawa_MSFTMicrosoft employee Monday, July 02, 2012 1:28 PM Moving it to a more appropriate forum (From:Testing with Visual Studio Test Manager (MTM))
    • Moved by Forrest GuoModerator Wednesday, July 18, 2012 3:54 PM version control API (From:Visual Studio Team System - Testing)
    Monday, July 02, 2012 4:31 AM

All replies