connect to tfs and download the files present in it VS2010

后端 未结 1 354
生来不讨喜
生来不讨喜 2020-12-21 19:45

I want to connect to TFS and download the files present in it. I am using VS2010 and tried the following code. But it seems I went wrong somewhere:

\"

相关标签:
1条回答
  • 2020-12-21 20:36

    Try something like this...

        static void Main(string[] args)
        {
            string teamProjectCollectionUrl = "http://myserver:8080/tfs/DefaultCollection";
            string serverPath = "$/My Project/My SubFolder";
            string localPath = @"c:\temp\download";
    
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
            VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
    
            foreach (Item item in versionControlServer.GetItems(serverPath, VersionSpec.Latest, RecursionType.Full, DeletedState.NonDeleted, ItemType.Any, true).Items)
            {
                string target = Path.Combine(localPath, item.ServerItem.Substring(2));
    
                if (item.ItemType == ItemType.Folder && !Directory.Exists(target))
                {
                    Directory.CreateDirectory(target);
                }
                else if (item.ItemType == ItemType.File)
                {
                    item.DownloadFile(target);
                }
            }
        }
    
    0 讨论(0)
提交回复
热议问题