Leggere dei file XML remoti
<%@ Page Language="c#" Debug="true" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
try
{
BindRSSFeeds("http://localhost/WebSite1/magazzino.xml");
}
catch (Exception ex)
{
//gestione errore
}
}
private XmlReader GetXMLContent(string ContentURL)
{
try
{
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(ContentURL);
wr.Timeout = 10000;
WebResponse resp = wr.GetResponse();
Stream stream = resp.GetResponseStream();
XmlTextReader reader = new XmlTextReader(stream);
reader.XmlResolver = null;
return reader;
}
catch (Exception ex)
{
//gestione errore
return null;
}
}
private void BindRSSFeeds(string inURL)
{
try
{
DataSet myRSSFeed = new DataSet();
myRSSFeed.ReadXml(GetXMLContent(inURL));
dataRSSItems.DataSource = myRSSFeed.Tables("item");
dataRSSItems.DataBind();
}
catch (Exception ex)
{
//gestione errore
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" ID="Head1">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="dataRSSItems" Runat="server" RepeatLayout="Table"
AlternatingItemStyle-BackColor=AliceBlue
SelectedItemStyle-BackColor=#ffff00
RepeatDirection="Vertical" RepeatColumns="1">
<SelectedItemStyle BackColor="Yellow"></SelectedItemStyle>
<ItemTemplate>
<asp:LinkButton ID="btnTitle" CssClass="subsubhead"
Text='<%#Container.DataItem("nome")%>' Runat="server"
CommandName="select">
</asp:LinkButton>
<br>
<asp:Label Runat="server" ID="lblRssDescription"
CssClass="normal" Text='<%#Container.DataItem("quantita")%>'>
</asp:Label>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
Scarica il Codice...
Stampa la pagina