Sorasyn commented on a Page, C# code to download webpage  -  Oct 11, 2013

Wouldn't it be best to throw an NullReferenceException or an ArgumentNullException instead of an ApplicationException with the only helpful data being a website URL?

 throw new ArgumentNullException("Command line arguments expected, but not found."); 
codegambit52  -  Oct 11, 2013

@SunnyD I think u r rite. Let me write an updated version of this snippet. Thanks for pointing it out.

Sorasyn  -  Oct 11, 2013

To be clear, does this just grab the page's resulting HTML code and print it onto the console in a giant glob of text and symbols? What is the purpose of doing so?

You could also rewrite the StreamReader code to use a "using" code block, which would forego the need to close both data, and reader, as they will both be closed automatically.

using (StreamReader sr = new StreamReader(client.OpenRead(args[0]))) {
   while (!sr.EndOfStream)
      Console.WriteLine(sr.ReadLine());
}
Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.