Click here to Skip to main content
13,763,835 members
Click here to Skip to main content
Add your own
alternative version


67 bookmarked
Posted 6 Jun 2011
Licenced CPOL

Displaying Videos from YouTube Channel in ASP.NET Website

, 8 Jun 2011
Rate this:
Please Sign up or sign in to vote.
How to display Videos from YouTube channel in ASP.NET website

Video from YouTube

[PLEASE BEWARE] While the overall concepts could be valid some years after the publication, some API details could have changed.


YouTube is firmly entrenched in our lives. Now, many users cannot imagine life without the use of this site. Due to the simplicity and ease of use, YouTube has become the most popular video sharing and one of the most popular websites in the world. Like many popular Google services, YouTube has Data API. This API allows you to interact with this service. This opens up great opportunities for developers of sites and various applications. Using this API, developers can query videos, search videos, upload videos on YouTube, create and read reviews and more.


Our goal is to query all the videos from YouTube channel of the famous Russian DJ and show them on the website.

Solution of the Problem

  1. To work with YouTube Data API, you need to download and install the Google Data API library. Then copy Google.GData.Client.dll, Google.GData.YouTube.dll, Google.GData.Extensions.dll files into the Bin folder of the website project and add references to them. How to do this was described in detail in my other article, Using Google Calendar in an ASP.NET website.
  2. To use all possibilities that YouTube Data API offered, you need to get Developer Key.
    Developer key uniquely identifies an application that will interact with the YouTube service. You can get it here.
  3. Let’s create a class to represent YouTube video on our site. The object of this class is a video that has properties: VideoId and Title.
    VideoId represents unique identifier for the video on YouTube and Title is the title of the video on YouTube:
    public class YouTubeVideoObject
           public string VideoId { get; set; }
           public string Title { get; set; }
  4. Let’s create a class that will interact with YouTube, and return us all the videos (objects of YouTubeVideoObject class) of channel:
    public class YouTubeVideoHelper
           const string YOUTUBE_CHANNEL = "BobinaMusic";
           const string YOUTUBE_DEVELOPER_KEY = "AI39si6JqO_f2b_JWSV3QUbcwg5S-1RJ4-
           public static YouTubeVideoObject[] GetVideos()
               YouTubeRequestSettings settings =
               new YouTubeRequestSettings("Bobina Channel", YOUTUBE_DEVELOPER_KEY);
               YouTubeRequest request = new YouTubeRequest(settings);
               string feedUrl = String.Format
               Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
               return (from video in videoFeed.Entries
                        select new YouTubeVideoObject()
                        {VideoId = video.VideoId, Title = video.Title}).ToArray();

    Description of Constants

    • YOTUBE_CHANNEL - Channel from which we will show videos
    • YOUTUBE_DEVELOPER_KEY - Developer key, obtained in step 2

    Description of GetVideos() Method

    To perform any action on YouTube Data API, it is necessary to create an object of YouTubeRequest class, passed an object of YouTubeRequestSettings class as a parameter to constructor. YouTubeRequestSettings class specifies application name (in fact, it is any string) and Developer key:

    YouTubeRequestSettings settings = 
    	new YouTubeRequestSettings("Bobina Channel", YOUTUBE_DEVELOPER_KEY);
    YouTubeRequest request = new YouTubeRequest(settings);

    Next, we need to compose URL from which we read the videos. After that, we use Get() method of YouTubeRequest class to get object of Feed class. This object contains a set of YouTubeEntry objects. Each object of YouTubeEntry class contains relevant information about the video:

    string feedUrl = String.Format
    Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));

    Then, we get an array of YouTubeVideoObject objects (this class has been created by us in step 3.) and return it from the method:

    return (from video in videoFeed.Entries select new YouTubeVideoObject()
    {VideoId = video.VideoId, Title = video.Title}).ToArray();      
  5. Now we have an array of videos (an array of YouTubeVideoObject objects). All we need to do is to show these videos on our web site. To do this, create the following code in aspx page of the website:
    <asp:Repeater ID="VideosRepeater" runat="server">
          <%# Eval("Title") %> <br />
          <object width="427" height="258">
               <param name="movie" value="
    		<%# Eval("VideoId") %>"></param>
               <param name="allowFullScreen" value="true"></param>
               <param name="allowscriptaccess" value="always"></param>
               <param name="wmode" value="opaque"></param>
               <embed src="<%# Eval("VideoId") %>?" 
    		type="application/x-shockwave-flash" width="427" 
    		height="258" allowscriptaccess="always" allowfullscreen="true" 
         <br />

    The code consists of object tag that allows to embed YouTube video in website. This code is wrapped into Repeater to list all obtained YouTube videos. Note that we use <%# Eval() %> data-binding expression, to get Title and VideoId of underlying YouTubeVideoObject object.

    After that, we just need to bind array of videos to Repeater control:

    protected override void OnLoad(EventArgs e)
               VideosRepeater.DataSource = YouTubeVideoHelper.GetVideos();

The result will look like this:

Video from YouTube


In this article, we examined the interaction with YouTube service to display videos from YouTube channel on our website. Data API provides a rich set of features to interact with YouTube. This opens up wide horizons for developers to be creative.


  • 6th June, 2011: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Igor Alekseev
Technical Lead UBS
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionThe videos where presented but sttoped Pin
Member 1063481826-May-14 7:51
memberMember 1063481826-May-14 7:51 
QuestionPlease sample on YouTube.V3 Pin
Truong Minh Tam4-Apr-14 18:20
memberTruong Minh Tam4-Apr-14 18:20 
QuestionDisplaying Videos from YouTube Channel in ASP.NET Website Pin
sheshu03627-Feb-14 0:51
membersheshu03627-Feb-14 0:51 
GeneralDisplaying Videos from YouTube Channel in ASP.NET Website Pin
sheshu03627-Feb-14 0:45
membersheshu03627-Feb-14 0:45 
GeneralThanks Pin
niravmmehta11-Jan-14 1:27
memberniravmmehta11-Jan-14 1:27 
QuestionFinally Pin
ojorma10-Jan-14 10:26
memberojorma10-Jan-14 10:26 
QuestionHow can I list all the videos Pin
demouser74321-Oct-13 1:09
memberdemouser74321-Oct-13 1:09 
GeneralMy vote of 4 Pin
Dholakiya Ankit6-Sep-13 1:43
memberDholakiya Ankit6-Sep-13 1:43 
QuestionGoogle API deprecated. How to do it with current method? Pin
Chas20035-Aug-13 8:55
memberChas20035-Aug-13 8:55 
Questionabout video display Pin
Member 824146616-Apr-13 8:21
memberMember 824146616-Apr-13 8:21 
QuestionOne confusion Pin
Anurag Sinha V5-Apr-13 11:22
memberAnurag Sinha V5-Apr-13 11:22 
GeneralMy vote of 5 Pin
dpalash15-Mar-13 3:25
professionaldpalash15-Mar-13 3:25 
QuestionNice article Pin
Sampath Sridhar1-Mar-13 23:22
memberSampath Sridhar1-Mar-13 23:22 
QuestionIs there an MVC method? Pin
danbeaulieu8-Feb-13 13:59
memberdanbeaulieu8-Feb-13 13:59 
BugIt's not load all list of channel videos Pin
k374628-Jan-13 7:20
memberk374628-Jan-13 7:20 
Questionhow to display thimbnail preview of videos Pin
deepaktri20-Jan-13 20:31
memberdeepaktri20-Jan-13 20:31 
GeneralMy vote of 5 Pin
Member 96642718-Dec-12 13:19
memberMember 96642718-Dec-12 13:19 
Questionthe source code is not downloaded. Pin
sugyani dash5-Sep-12 22:57
membersugyani dash5-Sep-12 22:57 
QuestionJust one video on time Pin
Zalemx1-Aug-12 8:26
memberZalemx1-Aug-12 8:26 
AnswerRe: Just one video on time Pin
26-Oct-12 12:03
suss26-Oct-12 12:03 
QuestionHow to know the user watch finish the video or not ? Pin
QBNetika27-Jul-12 1:13
memberQBNetika27-Jul-12 1:13 
GeneralMy vote of 5 Pin
Member 41481886-Jul-11 21:08
memberMember 41481886-Jul-11 21:08 
GeneralNice & Useful. Pin
alrsds14-Jun-11 6:21
memberalrsds14-Jun-11 6:21 
Generalexcellent article Pin
yuvachandra9-Jun-11 21:37
memberyuvachandra9-Jun-11 21:37 
GeneralMy vote of 5 Pin
Arlen Navasartian8-Jun-11 12:27
memberArlen Navasartian8-Jun-11 12:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06-2016 | 2.8.181113.4 | Last Updated 8 Jun 2011
Article Copyright 2011 by Igor Alekseev
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid