Previously, I blogged about “Displaying Selected YouTube Video Thumbnails On An ASP.NET Web Forms Page,” when you know the video IDs of the thumbnails you want to hyperlink.
A reader recently asked me how to hyperlink YouTube video thumbnails based on searching for a keyword. I promised to address that, so here goes.
- Form a simple request URL to the YouTube Data API that contains the appropriate search parameters;
- Use a WebRequest to send that URL to Google, which returns an XML document with results;
- Use WebResponse to dump that stream into an XmlDocument;
- Use XPath and XmlNode‘s SelectNodes method to recursively get the thumbnails from each entry; and
- Bind up a pile of Hyperlink controls, which are added dynamically to a Panel control.
Sounds more complicated than it actually is. Let’s do it.