How to embed YouTube video in c#

In this article, we will learn how to display /play YouTube video in browser or website. Here we pass string VideoUrl where we direct pass the YouTube channel url and if you want you can pass customize url then we you add a textbox and there we pass the values. And here we use on page load but you can also use click on button.

Source Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="youtubevedio.aspx.cs" Inherits="youtubevedio" %>

<!DOCTYPE html>

<html xmlns="">

<head runat="server">
    <form id="form1" runat="server">

    <div id="divVideo" runat="server">

Code behind:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class youtubevedio : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void SetVideoForPlay()
        string VideoUrl = "";
        string youcode = VideoUrl.Substring(VideoUrl.LastIndexOf("v=") + 2);
        if (youcode.Contains("&"))
            youcode = youcode.Substring(0, youcode.LastIndexOf("&"));
        string frame = @"<object width='{0}' height='{1}' data='{2}&autoplay=1' codetype='application/x-shockwave-flash'>
  &ltparam name='movie' value='{2}&autoplay=1' ></param></object>";
        string fWidth = "600px";
        string fHeight = "500px";
        divVideo.InnerHtml = String.Format(frame, fWidth, fHeight, youcode);

How to embed YouTube video in c# How to embed YouTube video in c# Reviewed by NEERAJ SRIVASTAVA on 5:54:00 PM Rating: 5

No comments:

Powered by Blogger.