csharp 简单的C#示例,用于连接Team Foundation Server存储库并从项目中下载文件。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 简单的C#示例,用于连接Team Foundation Server存储库并从项目中下载文件。相关的知识,希望对你有一定的参考价值。
/*
In addition to standard imports, you need:
System.IO;
System.Net;
Microsoft.TeamFoundation.Client;
Microsoft.TeamFoundation.Framework.Common;
Microsoft.TeamFoundation.Framework.Client;
Microsoft.TeamFoundation.VersionControl.Client;
*/
string username = "memyselfandi";
string password = "mysecretpassword";
string repository = "https://example.visualstudio.com/DefaultCollection";
// Step 1: Obtain server via authenticated connection to project collection.
NetworkCredential nc = new NetworkCredential(username, password);
Uri uri = new Uri(repository);
TfsClientCredentials tfsCredential = new TfsClientCredentials(new BasicAuthCredential(nc));
tfsCredential.AllowInteractive = false;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(uri, tfsCredential);
tpc.Authenticate();
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
// Step 2: Obtain item to be downloaded.
string projectName = "Top-level Folder";
string fileName = "ExampleFile.txt";
string itemPath = Path.Combine(projectName, fileName);
Item file = vcs.GetItems(String.Format(@"$/{0}", itemPath), RecursionType.None).Items.First<Item>();
// Step 3: Download item.
string destinationFolder = @"\Users\memyselfandi\Desktop";
using (Stream input = file.DownloadFile())
{
using (FileStream fout = File.Create(Path.Combine(destinationFolder, fileName)))
{
input.CopyTo(fout);
}
}
以上是关于csharp 简单的C#示例,用于连接Team Foundation Server存储库并从项目中下载文件。的主要内容,如果未能解决你的问题,请参考以下文章
csharp 用于找到斐波纳契数列的迭代解的示例。从计算机编程基础与C#http://www.introprogr
csharp 用于找到斐波纳契数列的迭代解的示例。从计算机编程基础与C#http://www.introprogr
csharp 使用LINQ 2 XML将XML数据条目解析为C#对象的简单示例
csharp C# - 简单的SerialPort单例类|示例:https://heiswayi.github.io/2016/csharp-simple-serialport-singleton-c
csharp C#超级简单记录器类//用法示例:https://heiswayi.nrird.com/2016/creating-super-simple-logger-class-in-csharp
csharp 用C#编写的简单SMTP邮件客户端助手类,用于异步发送电子邮件。注意:使用Log4Net进行日志记录。