0

What I am trying to do is find all .sql scripts pushed into my Test TFS Team Project during a specific timeframe AND then get either a link to view the file or download that copy OUTSIDE of my workspace. So I don't necessary want to get latest. This will be for an application to review all specifically .sql changes executed during a specific timeframe and then I will be comparing those files with a branched environment to determine which .sql where copied and ran against the database.

I am stuck on getting either a link to view the file or downloading the files. The problem I foresee with downloading the files is that I am going to download hundreds of files and what I really will end up doing to viewing each file to determine if I can re-run the .sql script against a different environment outside of Test.

 public void GetChangesets(DataTable files,
                           bool excludeManualDatabaseFiles,
                           bool containsExcludedDerictoriesAndFiles)
    {
        // this gets collection-lvl services, in contrast to TfsConfigurationServer (server-lvl)
        Uri serverUri = new Uri("<insert serverUri>");
        var tpc = new TfsTeamProjectCollection(serverUri);
        var vcs = tpc.GetService<VersionControlServer>();

        DateTime testDate;
        DateTime.TryParse("2017-07-01", out testDate);

        VersionSpec fromDateVersion = new DateVersionSpec(testDate);
        VersionSpec toDateVersion = new DateVersionSpec(DateTime.Now);

        vcs.QueryRootBranchObjects(RecursionType.Full);

        string teamProjectName = "<insert team project name>";
        TeamProject[] tps = new TeamProject[]
        {
            vcs.GetTeamProject(teamProjectName)
        };

        DataTable returnedChangesetDetail = new DataTable();
        // Step 1: THIS WORKS
        returnedChangesetDetail.Columns.Add("FileName");
        // Step 2: THIS DOES NOT WORK, this is currently empty !!!!!!
        returnedChangesetDetail.Columns.Add("Uri");


        foreach(TeamProject tp in tps)
        {
            IEnumerable changesets = vcs.QueryHistory(string.Concat("$/", tp.Name, "/Test/SQL"), 
                VersionSpec.Latest,
                deletionId: 0,
                recursion: RecursionType.Full,
                user: null,
                versionFrom: fromDateVersion,
                versionTo: toDateVersion,
                maxCount: int.MaxValue,
                includeChanges: true,
                slotMode: true);



            foreach(Changeset changeset in changesets)
            {

                foreach(Change change in changeset.Changes)
                {
                    string fileName = change.Item.ServerItem;
                    // I think this would be it but its not an accessible link, do I add/remove
                    // something to make this a Uri?
                    //var artifactUrui = change.Item.ArtifactUri; 

                    // Step 1: WORKING
                    lstbxFileNames.Items.Add(fileName);

                 }
            }

        }

    }

I hope that the comments explain what I am looking for. This will be an app for a non-dev but tech user to be able to review the changes needed in their environment. They will need to review approx 100 files and I was thinking a Uri would be an easy way for them to see the changes and then later select the files they need while disregarding changes found in Step 1 but determined not needed.

vfrank66
  • 1,318
  • 19
  • 28

1 Answers1

0

There isn’t the download URL of the file.

If your TFS version is TFS 2015 or higher, you can use version control Items REST API link (Make sure current user has permission to access target files)

Otherwise, you can provide a button/hyperlink with Path and version (date) arguments, then download the file (temp file) by using DownloadFile method and send the content stream (read content by stream) to client to let user save to local machine in button/hyperlink click event.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • What is the server path in this method? I would have thought it was Item.ServerItem but that seems to just throw an invalid file name exception. – vfrank66 Jul 12 '17 at 15:50
  • @vfrank66 It is ServerItem, works fine for me. Has this file been deleted? Does the code like this: DownloadFile(changeset.Item.ServerPath, changeset.Item.DeletionId, new DateVersionSpec(changeset.Item.CheckinDate), "D:\\d\\test.cs");? – starian chen-MSFT Jul 13 '17 at 02:01