I want to download the content of a .txt file located on my website to a string using c#.
I've tried with DownloadStringAsync(Uri, String)
, but it doesn't work and the string stays blank. If I try with string_name = DownloadStringAsync(Uri)
, it gives me the "cannot convert a void to a string" error.
I'm using the .NET Framework 3.5
Asked
Active
Viewed 697 times
0
-
Possible duplicate of [DownloadStringAsync wait for request completion](https://stackoverflow.com/questions/5071076/downloadstringasync-wait-for-request-completion) – mjw Jun 06 '17 at 20:50
-
@mjw Thank you, the solution to that question helped me too. – Jun 07 '17 at 16:58
1 Answers
0
Check System.Net.WebClient.DownloadString(url)
.
If you use Encoding you can set the WebClient's property inbefore to get the right result, and use .Dispose()
on the webclient afterwards.
-
The solution to [this question](https://stackoverflow.com/questions/5071076/downloadstringasync-wait-for-request-completion) was the answer I was searching for – Jun 07 '17 at 16:59
-
Well you only stated that you want to download a string. Nothing about why you'd want it to happen async here. Happy you found it though ^^ – Jun 07 '17 at 20:53
-