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:
"an object reference is required for the nonstatic field method" for GetItem() and CopyTo() methods
My code is not downloading all the files.
C# Code:
static void Main(string[] args)
{
string teamProjectCollectionUrl = "https://YourTfsUrl/tfs/YourTeamProjectCollection";
string filePath = "C:projectmyfile.cs";
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(teamProjectCollectionUrl));
VersionControlServer versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
Item item = versionControlServer.GetItem(filePath, VersionSpec.Latest);
string fileString = string.Empty;
using (Stream stream = item.DownloadFile())
{
using (MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
using (StreamReader streamReader = new StreamReader(new MemoryStream(memoryStream.ToArray())))
{
fileString = streamReader.ReadToEnd();
}
}
}
Console.WriteLine(fileString);
Console.ReadLine();
}
Could anybody please help me out getting the proper approach?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…