How to read an xml file which is in remote location using c#?

Posted by Soujanya21 under C# on 12/9/2010 | Points: 10 | Views : 8833 | Status : [Member] | Replies : 4
I am developing a console application using c#.In that application, I need to read an XML file which is there in another system(both the systems are in intranet).
Please,can anyone provide a code for this.

Thanks
Soujanya




Responses

Posted by: Lalji_mer on: 12/9/2010 [Member] Bronze | Points: 25

Up
0
Down
Try to below code sample

<%@ 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>


more info will get here

http://www.c-sharpcorner.com/uploadfile/mahesh/readwritexmltutmellli2111282005041517am/readwritexmltutmellli21.aspx

LP MER

Soujanya21, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 12/9/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Soujanya,

Refer those links..

Read a XML File from any URL...http://support.microsoft.com/kb/307643

Read a file from Server using FtpWebRequest object in your console application...Try this link for your reference...http://www.c-sharpcorner.com/uploadfile/neo_matrix/simpleftp01172007082222am/simpleftp.aspx

Cheers :)




Thanks,
T.Saravanan

Soujanya21, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chvrsri on: 12/9/2010 [Member] [Moderator] [MVP] Silver | Points: 25
Posted by: Chvrsri on: 12/10/2010 [Member] [Moderator] [MVP] Silver | Points: 25

Up
0
Down
This is the code snippet to read that xml file
The code i given here is referred from the above mentioned link.

Set oXH = Server.CreateObject("MSXML.ServerXMLHTTP")


oXH.open "GET", "http://www.otherserver.com/thefile.xml", false
oXH.send

Set oDOM = oXH.responseXML
' now oDOM contains the XML document from the other server


Hope this helps.

Thanks,
Radha Srikanth

Soujanya21, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response