C# get text from a URL
Go to solution
Solved by savstars,
Let me know if it helps. There are other ways, such as;
internal class WebTransfer : IWebTransfer, IDisposable { private WebClient _client; public WebTransfer() { _client = new WebClient(); } public string DownloadFileAsString(string url) { return _client.DownloadString(new Uri(url)); } public void Dispose() { if (_client != null) { _client.Dispose(); _client = null; } } }
or perhaps a more simplified version
string fileContents; using (WebClient client = new WebClient()) { fileContents = client.DownloadString(new Uri(@"http://localhost/directory/file")); }
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now