如何使用SharpSvn从SVN获取文件数据

时间:2015-01-12 06:03:05

标签: svn sharpsvn

例如在Svn中有一个包含'W​​elcome'的文件test.txt。我想要文件内部的数据,即“欢迎”,而不是导出文件。因为我想将它作为byte保存在Sql Server中。谢谢提前。

1 个答案:

答案 0 :(得分:4)

由于 svn cat 命令输出指定文件或URL(http://www-rohan.sdsu.edu/doc/svn-book-html-chunk/svn.ref.svn.c.cat.html)的内容,SvnSharp正在通过 SvnClient实现 cat 命令。 Write()https://sharpsvn.open.collab.net/wiki/SvnToSharpSvn),您可以使用以下C#代码将单个文件的内容作为字节数组获取:

Uri uri = new Uri("https://patn.to.your.svn.com/svn/filename.html");
SvnTarget target = SvnTarget.FromUri(uri);

MemoryStream mst = new MemoryStream();
SvnClient client = new SvnClient();
client.Authentication.ForceCredentials("username", "password"); 
client.Write(uri, mst);

byte[] content = mst.ToArray();

// to verify it is working, I have printed this to console; you will use above bytes to pass it to SQL or whatever
Console.Out.Write(System.Text.Encoding.Default.GetString(content));
相关问题