I have a uwp and i need to get text from a txt file saved on the internet to string I have a problem with download the file and get the text to string
Here's my code:
var webRequest = WebRequest.Create(@"http://yourUrl");
using (var response = webRequest.GetResponse())
using (var content = response.GetResponseStream())
using (var reader = new StreamReader(content))
{
var strContent = reader.ReadToEnd();
}
can anyone help me?
var url = "http://example.com/abc.txt";
var textFromFile = (new WebClient()).DownloadString(url);
I find an answer to my question
I've to download the txt file to my local storage and after that i read them from my local
Here's the code that i used to download the file to my local folder
var uriBing = new Uri(@"https://your/abc.txt");
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await storageFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting);
var cli = new HttpClient();
Byte[] bytes = await cli.GetByteArrayAsync(uriBing);
IBuffer buffer = bytes.AsBuffer(); await Windows.Storage.FileIO.WriteBufferAsync(sampleFile, buffer);
Thanks for helping hope this will help anyone look for something like this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With