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);
3

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for helping me out! The "new" isn't actually in my code, I accidently copy pasted the wrong line and forgot to edit it out :P
Does it work for you now? If it is the answer you were looking for, mark it as "answer". otherwise, help me help you :)
No :( No file is being written for some reason. Any idea?
What exception are you getting?
Ok, so I rebooted Visual Studio as an admin and that seemed to work. Seeing as your code worked, I will mark yours as the solution :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.