Download you-tube API dll from: Here. Add below code on upload button:
YouTubeRequestSettings setting = new YouTubeRequestSettings("app name anything u like", "Your Developer Key", "Your youtube username", "youtube a/c passowrd");
YouTubeRequest request = new YouTubeRequest(setting);
Video newVideo = new Video();
newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("D:\\Demo\\YoutubeVideoUpload\\e3a6f15f-4a8c-40d5-9cc8-c45d30b7f9ed.mov", "video/quicktime");
Video createdVideo = request.Upload(newVideo);
Retrieve uploaded videos
videos.aspx.cs :
private string YouTubeChampionshipChannel;
private string YouTubeClientID;
private string YouTubeDeveloperKey;
public string YouTubeMovieID;
public DataTable dtVideoData = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
//Pass User Name to the YouTube link
YouTubeChampionshipChannel = "prakashrthd";
//Add the YouTube Developer keys.
//Register a Developer Key at: http://code.google.com/apis/youtube/dashboard
YouTubeClientID = "prakashrthd@gmail.com";
YouTubeDeveloperKey = "AI39si4EpdRFuvaGm8WNIBIHPmpSfiT7Qmy_WIfhDz3OrLmTwqS0lX_8lcCmBTKq-spys_TfQ8ysWRyg9kB5nFYCifmzgPlFKw";
CreateVideoFeed();
//Assign the first video details on page load.
if (String.IsNullOrEmpty(YouTubeMovieID))
{
YouTubeMovieID = dtVideoData.Rows[0]["VideoID"].ToString();
lblDescription.Text = dtVideoData.Rows[0]["Description"].ToString();
}
}
private void CreateVideoFeed()
{
YouTubeRequestSettings settings = new YouTubeRequestSettings("prakashtest", "AI39si4EpdRFuvaGm8WNIBIHPmpSfiT7Qmy_WIfhDz3OrLmTwqS0lX_8lcCmBTKq-spys_TfQ8ysWRyg9kB5nFYCifmzgPlFKw", "prakashrthd@gmail.com", "!loveyougod");
YouTubeRequest request = new YouTubeRequest(settings);
//Link to the feed we wish to read from
string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?orderby=published", YouTubeChampionshipChannel); ;
dtVideoData.Columns.Add("Title");
dtVideoData.Columns.Add("Description");
dtVideoData.Columns.Add("DateUploaded");
dtVideoData.Columns.Add("Ratings");
dtVideoData.Columns.Add("NoOfComments");
dtVideoData.Columns.Add("VideoID");
dtVideoData.Columns.Add("Duration");
DataRow drVideoData;
Feed videoFeed = request.Get(new Uri(feedUrl));
//Iterate through each video entry and store details in DataTable
foreach (Video videoEntry in videoFeed.Entries)
{
drVideoData = dtVideoData.NewRow();
drVideoData["Title"] = videoEntry.Title;
drVideoData["Description"] = videoEntry.Description;
drVideoData["DateUploaded"] = videoEntry.Updated.ToShortDateString();
drVideoData["Ratings"] = videoEntry.YouTubeEntry.Rating == null ? "0" : Convert.ToString(videoEntry.YouTubeEntry.Rating.Average);
drVideoData["NoOfComments"] = Convert.ToString( videoEntry.CommmentCount);
drVideoData["VideoID"] = videoEntry.YouTubeEntry.VideoId;
drVideoData["Duration"] = Convert.ToString(videoEntry.YouTubeEntry.Duration.Seconds);
dtVideoData.Rows.Add(drVideoData);
}
repVideoList.DataSource = dtVideoData;
repVideoList.DataBind();
}
protected void repVideoList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drVideo = (DataRowView)e.Item.DataItem;
LinkButton showVideo = (LinkButton)e.Item.FindControl("btnShowVideo");
Literal title = (Literal)e.Item.FindControl("Title");
Literal description = (Literal)e.Item.FindControl("Description");
Literal ratings = (Literal)e.Item.FindControl("Ratings");
Literal noOfComments = (Literal)e.Item.FindControl("NoOfComments");
Literal duration = (Literal)e.Item.FindControl("Duration");
showVideo.CommandArgument = drVideo["VideoID"].ToString();
title.Text = drVideo["Title"].ToString();
description.Text = drVideo["Description"].ToString();
ratings.Text = drVideo["Ratings"].ToString();
noOfComments.Text = drVideo["NoOfComments"].ToString();
duration.Text = drVideo["Duration"].ToString();
}
}
protected void repVideoList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
// Pass the YouTube movie ID to flash
YouTubeMovieID = e.CommandArgument.ToString();
if (YouTubeMovieID == e.CommandArgument.ToString())
{
lblDescription.Text = ((Literal)e.Item.FindControl("Description")).Text;
}
}
Download full source code: here