In this post I would like to highlight how easy it is to connect to SVN repository using DotSVN.
Steps to follow:
1) Create an instance of ISVNRepository
using the SVNRepositoryFactory
.
// The path to the root of an SVN FSFS repositorystring repositoryPath = "file://" + "SomeValidPathToFSFS";// Creates an ISVNRepository driver according to the protocol// that is to be used to access a repository.ISVNRepository repository = SVNRepositoryFactory.Create(new SVNURL(repositoryPath));repository.OpenRepository();
2) Now that we have a connection to the repository, we can get contents using the GetDir
method.
// Dictionary to receive the SVN propertiesIDictionary<string, string> properties = new Dictionary<string, string>();// Now we call GetDir to get the contents at the specified path// Here we specified an empty string to get the contents of the root// Second argument is the version, -1 indicated the latest version// Third argument is the property collectionICollection<SVNDirEntry> dirEntries = repository.GetDir("", -1, properties);
The SVNDirEntry
representation of a versioned directory entry, It contains
3) Now we can iterate through the SVNDirEntry
collection.
foreach (SVNDirEntry dirEntry in dirEntries){string DirName = dirEntry.Name;System.Diagnostics.Debug.WriteLine(DirName);}
And that is it. We can also call other methods in the repository like
// Gets the Universal Unique IDentifier (UUID) of this repositorystring repostoryUUID = repository.GetRepositoryUUID(true);// Returns the latest revision of this repositorylong latestRev = repository.GetLatestRevision();