Embed YouTube Video into WebPage using ASP.NET

Hello Developers,

Here is the code for Embedding YouTube video into ASP.NET site.

Embed is a term used to describe an object that is independent and does not need an external program or device to run it. For instance, in Web page design, one can link to or insert a video image or sound file into the page so that it is hyperlinked and clickable. When click on, the video image or sound file is played as the operation system usually contains a built-in multimedia application to play it.

/// YouTube video player  script generator

public static string GenerateScript(string videoId, int autoPlay, int width, int height){

StringBuilder sb = new StringBuilder();

sb.Append(@”<embed src=’http://www.youtube.com/v/“);



// set autoplay options


sb.Append(“‘ “);

sb.Append(“type=’application/x-shockwave-flash’ “);

sb.Append(“allowscriptaccess=’never’ enableJavascript =’false’ “);

sb.Append(“allowfullscreen=’true’ “);

// set width

sb.Append(“width='” + width.ToString() + “‘ “);

// set height

sb.Append(“height='” + height.ToString() + “‘ “);


string embedScript = sb.ToString();

return embedScript; }

This function returns the string as below

<embed src=’http://www.youtube.com/v/XP9tzWtLFus&autoplay=0


allowscriptaccess=’never’ enableJavascript =’false’

allowfullscreen=’true’ width=’640′ height=’480′ ></embed>

Below are few samples on this:

Thanks for Reading this article.

With personal regards



2 thoughts on “Embed YouTube Video into WebPage using ASP.NET

  1. Hi Swagat,

    Thanks for submitting these interesting blogs. Youtube code is really easy to understand and I implemented also.

    Thanks again.

    • Hi Subhashis,

      Thanks for reading my articles. Let me know if I can help you in any other technical challenges. I’ll be happy to resolve the issues you face or giving any solution to your technical worries.

      With Personal Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s