Get xml from a URL

Get xml from a URL

Hi all,
Using HTTPWebRequest and Response, we can easily get the xml file. FYI, see the below code.

First of all, we need to add the following namespaces in our application.

using System.Xml;
using System.IO;
using System.Text;
using System.Net;

Just copy the following code in your button_click event (or as your wish whichever event).

string url = "your url";
Uri fileUrl = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader reader = new StreamReader(receiveStream, encode);
string strValue = reader.ReadToEnd();


Now the whole xml file in strValue variable.

...S.VinothkumaR.

1 comment:

Unknown said...

Hello, I have one problem when I develop a bluetooth(USB Dongle) application in WINCE 5.0.
My MSN is joenkin@hotmail.com.
Can u add me?
Thks!