Home > Programming > C# Read a file from web (http)

C# Read a file from web (http)

Recently, I had a friend at work who was trying to read an xml file saved in an svn repository. He had the repository link and wanted to just use it to read the xml and parse it.

Here is a way I found to do it using WebClient in C#.


string path = @"http://11.1.11.11/svn/test.xml";

WebClient webClient = new WebClient();
 Stream stream = webClient.OpenRead(path);
 if (stream != null)
 {
 StreamReader sr = new StreamReader(stream);
 string text = sr.ReadToEnd();
 txtContents.Text = text;
 }

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: