【问题标题】:C# download xml from a github repositoryC# 从 github 存储库下载 xml
【发布时间】:2019-07-31 10:06:00
【问题描述】:

我有一个已上传到我的 GitHub 存储库的 XML 文件。 但是,我不知道如何使用 C# 将它下载到我的电脑上

有人可以帮忙吗?

链接到 XML 文件 https://github.com/Belchuke/BQuizz-With-Buzzers/blob/master/QuizzQuestions.xml

我试过了

string xml = new WebClient().DownloadString(@"https://github.com/Belchuke/BQuizz-With-Buzzers/blob/master/QuizzQuestions.xml");

XDocument dco = XDocument.Parse(xml);
dco.Save("testXML.xml");

这如何在第 44 行发送异常

【问题讨论】:

标签: c# xml github download


【解决方案1】:

当您尝试从 Github、Gitlab 等 git 存储库下载文件时,您必须使用 原始地址(它只会显示文件而不是所有的html页面)。

string xml = new WebClient().DownloadString(@"https://raw.githubusercontent.com/Belchuke/BQuizz-With-Buzzers/master/QuizzQuestions.xml");
XDocument dco = XDocument.Parse(xml);
dco.Save("testXML.xml");

【讨论】:

  • @Belcookies 没问题,如果它符合您的需要,请验证答案。
  • 我会在 5 分钟内完成 :)
【解决方案2】:

您必须更改 URL 才能下载行 XML,试试这个

https://raw.githubusercontent.com/Belchuke/BQuizz-With-Buzzers/master/QuizzQuestions.xml

string xml = new WebClient().DownloadString(@"https://raw.githubusercontent.com/Belchuke/BQuizz-With-Buzzers/master/QuizzQuestions.xml");

        XDocument dco = XDocument.Parse(xml);
        dco.Save("testXML.xml");

【讨论】:

  • 由于this answer 具有相同的内容,因此该答案不会向该线程添加任何新内容。
猜你喜欢
  • 2019-12-04
  • 1970-01-01
  • 2021-03-23
  • 2017-02-03
  • 2021-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多