如何从服务而不是本地路径读取XML [英] How to read XML from service and not local path

查看:77
本文介绍了如何从服务而不是本地路径读取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,我有一个webform,我正在尝试从XML URL获取数据。

当我从本地项目中读取XML文件但是当我尝试阅读时它不起作用来自网址。

我在这里做错了什么?



我尝试了什么:



这个有用:



protected void Page_Load(object sender,EventArgs e)

{

DataSet ds = new DataSet();

ds.ReadXml(Server.MapPath(MynewXML.xml));

DetailsView2.DataSource = ds .Tables [0] .DefaultView;

DetailsView2.DataBind();

}



这不是work:



protected void Page_Load(object sender,EventArgs e)

{

DataSet ds = new DataSet ();

ds.ReadXml(Server.MapPath(http://myservername.mydomain.com/my-services/user/MynewXML.xml));

GridView4.DataSource = ds.Tables [0] .DefaultView;

GridView4.DataBind();

}

Hello everyone, i have a webform where i'm trying to get data from a XML URL.
It works when i read the XML file from my local project but not when i try to read from the URL.
What am i doing wrong here?

What I have tried:

This works:

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("MynewXML.xml"));
DetailsView2.DataSource = ds.Tables[0].DefaultView;
DetailsView2.DataBind();
}

This does not work:

protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("http://myservername.mydomain.com/my-services/user/MynewXML.xml"));
GridView4.DataSource = ds.Tables[0].DefaultView;
GridView4.DataBind();
}

推荐答案

引用:

ds.ReadXml(Server.MapPath("http://myservername.mydomain.com/my-services/user/MynewXML.xml"));

当文件结束时互联网,你不能只是打开它阅读,因为它不适合你。

你首先需要从服务器下载文件。

When a file over internet, you can't just open it and read, because it is not available to you.
You first need to download the file from server.


这篇关于如何从服务而不是本地路径读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆