使用 SharpSVN 读取文件时出现问题

发布于 2024-10-09 12:21:53 字数 1234 浏览 6 评论 0原文

我在使用 SharpSVN api 时遇到问题。当我尝试使用 SvnClient.Write() 或 SvnClient.Export() 时,出现以下错误:

存储库 URL 格式错误

我的代码如下

using(SvnClient client = new SvnClient())
        {
            MemoryStream ms = new MemoryStream();
            client.Authenticator.DefaultCredentials = new NetworkCredential("master","master");
            SvnTarget t1 = new SvnUriTarget(new Uri("http://ETAB-APP:81/repositorio/"));
            SvnTarget t2 = new SvnUriTarget(new Uri("http://ETAB-APP:81/repositorio/Registro e Controle Acadêmico/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf"));

            client.Write(t2, ms);
            client.Export(t2, "C:\\chups");


        }

这让我发疯,因为如果我尝试使用 t1 作为 SvnTarget 来执行此方法,一切都会正常。但问题是,每次我想获取特定文件时,我无法导出所有存储库。

我尝试在 URL 名称前添加一个“@”,即

http://@ETAB-APP:81/repositorio/Registro 学术控制/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf

但没有任何反应。

我做错了什么?

PS:抱歉,如果我犯了任何错误,我是巴西人,我的英语不是很好

I am having an issue with the SharpSVN api. When I try to use SvnClient.Write() or SvnClient.Export(), the following error occurs:

Malformed URL for repository

My code is the following

using(SvnClient client = new SvnClient())
        {
            MemoryStream ms = new MemoryStream();
            client.Authenticator.DefaultCredentials = new NetworkCredential("master","master");
            SvnTarget t1 = new SvnUriTarget(new Uri("http://ETAB-APP:81/repositorio/"));
            SvnTarget t2 = new SvnUriTarget(new Uri("http://ETAB-APP:81/repositorio/Registro e Controle Acadêmico/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf"));

            client.Write(t2, ms);
            client.Export(t2, "C:\\chups");


        }

It's driving me insane because if I try to execute this method using t1 as SvnTarget, everything works fine. But the problem is that I can't export all the repository everytime I want to get an especific file.

I tried to put an "@" before the name of URL i.e.

http://@ETAB-APP:81/repositorio/Registro e Controle Acadêmico/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf

but nothing happens.

What am I doing wrong?

PS: Sorry if I did any mistake, I am brazilian and my english is not very good

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一曲琵琶半遮面シ 2024-10-16 12:21:53

我发现,如果您只是将任意 URL 传递给 Uri 对象构造函数,它将创建一个 SVN 无法理解的无效 Uri。这可能是由于外来字符或转义了默认 Uri 对象构造函数不需要转义的某些字符。

使用 UriBuilder 对象将 Uri 分解为多个部分,然后将生成的 Uri 传递给 SVN。

// Build Uri by explicitly specifying the constituent parts. 
UriBuilder uriBuilder = new UriBuilder("http", "ETAB-APP", 81, "/repositorio/Registro e Controle Acadêmico/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf");

using(SvnClient client = new SvnClient())
{
    MemoryStream ms = new MemoryStream();
    client.Authenticator.DefaultCredentials = new NetworkCredential("master","master");
    SvnTarget t2 = new SvnUriTarget(uriBuilder.Uri);
    client.Write(t2, ms);
    client.Export(t2, "C:\\chups");
}

What I have found is that if you simply pass an arbitrary URL to the Uri object constructor, it will create an invalid Uri that SVN does not understand. This can be due to foreign characters or escaping of certain characters that does not need to be escaped by the default Uri object constructor.

Break up the Uri into its parts by using the UriBuilder object and then pass the resulting Uri to SVN.

// Build Uri by explicitly specifying the constituent parts. 
UriBuilder uriBuilder = new UriBuilder("http", "ETAB-APP", 81, "/repositorio/Registro e Controle Acadêmico/Administração/0000/Dossiê do Aluno - ADEMIR JOSPE SANGALLI - (2001193) - Curso (000)/DOC ADICIONAL(264839).pdf");

using(SvnClient client = new SvnClient())
{
    MemoryStream ms = new MemoryStream();
    client.Authenticator.DefaultCredentials = new NetworkCredential("master","master");
    SvnTarget t2 = new SvnUriTarget(uriBuilder.Uri);
    client.Write(t2, ms);
    client.Export(t2, "C:\\chups");
}
贪恋 2024-10-16 12:21:53

当我调用 Sharpsvn 通过 url(包含“&”和“/”结尾)获取 svn 信息时。sharp svn 抛出异常。

谢谢斯布罗格斯:

需要转义网址吗? SVN Api 可能会为你做这件事,但是它
可能值得尝试运行它
msdn.microsoft.com/en-us/library/… – sbrogers 2010 年 12 月 29 日 14:05

我使用此代码

SvnUriTarget repos = new SvnUriTarget(myUrlString.TrimEnd(new char[] { '/' }));

我的问题已解决

when I call sharpsvn to get svn info by url (that contains '&',and end of '/').sharp svn throw an exception.

thanks sbrogers :

Do you need to escape the url? The SVN Api may do it for you, but it
might be worth trying running it through
msdn.microsoft.com/en-us/library/… – sbrogers Dec 29 '10 at 14:05

I use this code

SvnUriTarget repos = new SvnUriTarget(myUrlString.TrimEnd(new char[] { '/' }));

my problem is resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文