Tuesday, 23 July 2013

How to Upload YouTube Video and Show it In DataListin Asp.net Using C#

When you want to upload YouTube video in your server and want to display it in your web page then before this you will have to convert the YouTube link in embedded link because ifram tag of html supports this.
How yo will get embedded YouTube video link. Look at the below picture.
The selected text in the picture is embedded link of this video, you can get this by clicking on share text as this is obvious in picture.
Since user will upload only URL got in web page you will have to convert it in embedded URL. How you will convert youtube url in embedded?
if you are using C# then do link this. 
        string s = TextBox1.Text; // text box in which user enters Youtube URL
        string g = "embed/";
        string o = "watch?v=";
        string m = s.Replace(o, g); // finally we get m as a embedded URL to store in database.

With the help of sql command you can easily store this string m in your database.

How to display these videos in aspx page?


 <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="4" RepeatDirection="Horizontal">
     <ItemTemplate>
             <table runat="server">
                   <tr>
                       <td>
                            <iframe runat="server" src='<%#Eval("VideoLink") %>'></iframe>
                       </td>
                    </tr>
       
              </table>
       </ItemTemplate>
  </asp:DataList>


on the code behind page you can bind data list with sql data source using SQL Command.

hope this will work. thank you!...