Como obter o ficheiro xml do url [duplicado]
[[2] esta pergunta já tem uma resposta aqui:
- Como posso baixar um ficheiro XML usando C#? 3 respostas
Quero descarregar o ficheiro xml no botão ou ligar carregue em link, porque estou a usar a grelha no formulário web, quando carregar no botão ou ligar, irá abrir o ficheiro xml na página nova, à medida que o quiser transferir.Estou usando url http (eg. http://SomeName/XmlFiles/1554263.xml)
0
Author: Dinesh Pareek, 2016-12-27
2 answers
Isto pode servir-te de consolo.
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile("http://SomeName/XmlFiles/1554263.xml", "some.xml");
}
WebClient.Transfere o ficheiro para um ficheiro local a partir do URI indicado no parâmetro endereço. Este método bloqueia ao transferir o recurso. Para baixar um recurso e continuar a executar enquanto espera pela resposta do servidor, use um dos métodos de download Fileasync.
Editar
SaveFileDialog savefile = new SaveFileDialog();
// set a default file name
savefile.FileName = "unknown.xml";
if (savefile.ShowDialog() == DialogResult.OK)
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.DownloadFile("http://SomeName/XmlFiles/1554263.xml", savefile.FileName);
}
}
0
Author: Mohit Shrivastava, 2016-12-27 06:50:51