R
Rahul 11
Guest
Hi,
I am a SSIS developer, but very new to C# coding. I have got a new requirement where I need to write a C# code to connect to TFS path and download the files from TFS to our local path or shared network. I am using the below code which I found from the link below but it is not working as expected, can anyone suggest me where am I going wrong?
connect to tfs and download the files present in it VS2010
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);
}
}
}
The above code is looping through the files what I have on the TFS, but it doing nothing for item.DownloadFile(target); Please help me out with this.
Thanks!
Rahul
Continue reading...
I am a SSIS developer, but very new to C# coding. I have got a new requirement where I need to write a C# code to connect to TFS path and download the files from TFS to our local path or shared network. I am using the below code which I found from the link below but it is not working as expected, can anyone suggest me where am I going wrong?
connect to tfs and download the files present in it VS2010
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);
}
}
}
The above code is looping through the files what I have on the TFS, but it doing nothing for item.DownloadFile(target); Please help me out with this.
Thanks!
Rahul
Continue reading...