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

How to Get Data of Files From SVN using SharpSvn

例如,在 Svn 中有一个包含 'Welcome' 的文件 test.txt。我不导出文件,而是想要文件中的数据,即 'Welcome'。因为我想提前将它保存在Sql服务器中作为byte.Thanks。

由于svn cat命令输出指定文件或URL(http://www-rohan.sdsu.edu/doc/svn-book-html-chunk/svn.ref.svn.c.cat.html), and SvnSharp is implementing cat command via SvnClient.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));