Get text from txt file on the internet

前端 未结 2 1561
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 15:44

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 co

相关标签:
2条回答
  • 2021-01-06 16:30

    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

    0 讨论(0)
  • 2021-01-06 16:38
    var url = "http://example.com/abc.txt";
    var textFromFile = (new WebClient()).DownloadString(url);
    
    0 讨论(0)
提交回复
热议问题