user3035181
user3035181

Reputation: 101

Load text file from url into an array

I am currently using

string[] defaultcommands = (File.ReadAllLines(@"commands"));

to load a local files contents in the solution as an array. I want to be able to update the contents of that file from my workstation and it take effect on all instances running. To do this, I'd like to load the default command file from a url like: https://mywebsite.com/assistant/commands.txt. I tried string[] defaultcommands = (File.ReadAllLines(@"https://mywebsite.com/assistant/commands.txt")); but it doesn't understand how to handle the URL I guess. It comes back with: System.NotSupportedException.

How can I load a text file from a URL into an array?

Upvotes: 0

Views: 682

Answers (1)

rhughes
rhughes

Reputation: 9583

Have a look at the WebClient class.

It gives this example:

WebClient client = new WebClient ();
string reply = client.DownloadString (address);

Console.WriteLine (reply);

Upvotes: 2

Related Questions