Search code examples
svnsharpsvn

How to Get Data of Files From SVN using SharpSvn


For example in Svn there is a file test.txt that contains 'Welcome'. Instead of exporting the file , I want data inside the file , that is 'Welcome'. Because i want to save it in Sql Server as byte.Thanks In advance.


Solution

  • As svn cat command outputs the contents of the specified files or URLs (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), you can use following C# code to get the content of the single file as byte array:

    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));