Friday, 16 August 2013

Upload and Display YouTube Video in Asp.Net

In this tutorial I will teach you how to upload youtube video in database and display it in various style in web page in using C#.

So, here we go...
Make a database table with any name as you wish and give three column
1. ID which will be primary key and will auto increase.

2. UserID user name either from session or from simple inserting name every time when upload video.

3. VideoLink for storing video link from youtube page.

YouTube video will not play on you web page until you convert it in embedded video so how to check which video is embedded and which one is not. look at the image

but when a user upload or share any youtube video he or she will not upload embedded video but he or she will upload simple URL of any video so we need to convert general URL in embedded URL by this way using C#.
string s = TextBox1.Text
string g = "embed/";
        string o = "watch?v=";
        string m = s.Replace(o, g);
  Here string s contains the URL of text box in which user will enter URL of youtube video. With the help of Replace function of C# we will convert this to embedded URL and send it to database. by normal way of inserting data in database. Like this