Friday, April 11, 2008

Download HTTP Resource Without Browser

Today I saw a Silverlight video player that I liked. I wanted to see its source XAML. I got the link (http://www.asp.net/SilverlightPlayer/xaml/videoplayer.xaml). But when I put it into IE or FireFox, I got an error because the browser tries to load it using WPF. Anyway, I kept trying and couldn't figure out how to just download the xaml. If there is a shortcut (which I'm sure there is), I'd like to know.

In the meantime, I wrote a small console app that downloads some url and saves it to a local file. It's only a few lines. Create a new console app and use the following code:


class Program

{

static void Main(string[] args)

{

string uri = args[0];

string filePath = args[1];

byte[] bytes = (new WebClient()).DownloadData(args[0]);

File.WriteAllBytes(filePath, bytes);

}

}



That's it. Using that I was able to get my xaml. Gotta love that .net framework!

No comments: