0

I am trying to download the contents of this webpage into my program. I have tried using WeblClient.DownloadString, WebClient.DownloadFile, then save it to a file and read it from a local file, but none of this is working. When I use breakpoints in Visual Studio, I see the string is correctly saved, but when I try to print it to a file, or print it to the console, nothing is displayed.

What I am aiming to do is download this webpage's content into a String then parse it with JSON.NET.

Here is my attempt to save it to a file:

         WebClient webpage = new WebClient();


         var html = webpage.DownloadString("https://api.fixer.io/latest");
         String k = html;


          File.WriteAllText(@"C:\Users\JCena\Desktop\Hell1o.txt", k);
Cratherton
  • 17
  • 1
  • 9

1 Answers1

0

You code is almost fine. first, get rid of the "new" keyword. second, make sure you don't have exception for permissions for the folder specified.

try that code:

     WebClient webpage = new WebClient();

     var html = webpage.DownloadString("https://api.fixer.io/");
     String k = html;

     File.WriteAllText(@"Hello.txt", k);
Roi Katz
  • 575
  • 4
  • 14