将文件从TFS下载到本地文件夹时,操作异常无效

时间:2015-09-09 12:53:41

标签: c# visual-studio-2010 tfs

我有一个代码可以将文件从TFS下载到本地文件夹但是收到错误: InvalidOperationException:路径$ / My Project / Something不是文件。由于我对这个概念不熟悉,你能帮助我解决这个问题吗?

代码:

static void Main(string[] args)
{
    string teamProjectCollectionUrl = "http://myserver:8080/tfs/DefaultCollection";
    string serverPath = "$/My Project";
    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);
        }
    }
}

在向TFS添加文件时分配路径是错误的吗?

以下链接:

将文件添加到TFS“http://blogs.msdn.com/b/jasonz/archive/2009/10/21/tutorial-getting-started-with-tfs-in-vs2010.aspx

代码取自“connect to tfs and download the files present in it VS2010

0 个答案:

没有答案