从C#.net中的SVN Repository下载文件

Mic*_*per 2 asp.net tortoisesvn download

如何从C#.net中的Web应用程序下载SVN存储库中的文件?我想以编程方式下载文件.单击按钮时,它应从TextBox中给出的URL下载文件.

wat*_*ewp 6

首先,您应该能够直接在存储库上访问(只读)文件,而无需SVN客户端(尽管您可能需要身份验证).在这种情况下,它就像从任何URL下载任何文件:

using (WebClient client = new WebClient())
{
    // In case you need authentication...
    // client.Credentials = new NetworkCredential("username", "password");

    client.DownloadFile(fileUrl, localDestinationPath);
}
Run Code Online (Sandbox Code Playgroud)

然而,就像Vinayak所说,SharpSvn并不是一个糟糕的方式 - 它对于处理SVN交互非常有用.因此,如果使用标准WebClient不起作用,您可以在SharpSvn中执行以下操作来获取文件流:

MemoryStream stream = new MemoryStream();
using (SvnClient client = new SvnClient())
{
    client.Authentication.DefaultCredentials = new NetworkCredential("username", "password");
    client.Write(SvnTarget.FromUri(svnFilePath), stream);
}
return stream;
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!