I've searched for two days for a way that when you press a button (In this case button15) that when its pressed, it will retrieve a .txt from online. Basically I need to turn this:

DirectoryInfo di = new DirectoryInfo("C:\\");
            FileInfo[] rgFiles = di.GetFiles("*.dll");
            foreach (FileInfo fi in rgFiles)
            {
                listBox3.Items.Add(fi.Name);
            }

So instead of getting it from the Directory, it gets it from online. Any way of doing this?

Edited 6 Years Ago by Ims333: n/a

4 Hours, 0 Replies. You can't be serious. This site must is horrible. I try getting a little help, and 0 replies. ITS BEEN 4 HOURS, IS EVERYONE DEAD? God this site is terrible.

It is distinctly possible that nobody who's viewed the question happens to know an answer to it off the top of their heads and that would be why you haven't received an answer. Also, not every member on this site is on 24 hours a day to check for questions the second they hit the forums.

Many questions of varying difficulty are answered successfully on this site every hour so I don't believe it's a matter of the quality of the site :)

On that note, I don't believe DirectoryInfo has the capacity to browse URLs per-se as it is designed for local/network file management.

That being said, this tutorial has some information on how to do something similar to what you're asking for, it has both VB and C# examples.

Sorry I wasn't able to Google that for you sooner.

Hope this helps :) Please remember to mark threads solved once your issue is resolved.

Edit: By the way... um... it's Saturday... Just because people are coders doesn't mean they don't have lives ;)

Edited 6 Years Ago by Lusiphur: n/a

I looked around and couldn't find the answer. Thanks very much. :D Thanks, if this doesn't work I'll use that Google link. Thanks!

Instead of using a load file from online, I used a download then load.

downloadSiteData("http://www.artilleryhacks.com/ca/pub/combatarms_available.txt");
                FileStream newFile = new FileStream("C:\\Hacks\\combatarms_available.txt", FileMode.Create);
                newFile.Write(downloadedData, 0, downloadedData.Length);
                newFile.Close();

                FileInfo file = new FileInfo("C:\\Hacks\\combatarms_available.txt");
                StreamReader stRead = file.OpenText();
                while (!stRead.EndOfStream)
                {
                    listBox3.Items.Add(stRead.ReadLine());
                }

Edited 6 Years Ago by Ims333: n/a

That works too...

Only thing you'll want to be careful of there is, in the event that you're downloading on more than one occasion, you'll need to change the FileMode such that it can overwrite the existing file or add a method for creating a unique file-name if you're downloading the file again but want to keep the previous copy as well.

Currently the code you have (if I recall my filemodes correctly) will create the text file the first time around but will then encounter an error on a 2nd attempt as the file will already exist.

Other than that, glad you found a working solution :) Please don't forget to mark the thread solved if your issue is resolved.

This article has been dead for over six months. Start a new discussion instead.