HomeDevelopment (Old) Allow embedded youtube video in blog post content (as content editor...

[SharePoint 2010 – Developpement] Allow embedded youtube video in blog post content (as content editor webpart), with new embedded youtube code (iframe) for SharePoint 2010 blog post

What is that ?

Based on this excellent tutorial from kirk Evans : http://blog.evepoints.com/2010/11/add-video-sharepoint-2010-blog.html
This will allow you to add youtube video in a blog content.
Basic sharepoint feature permit you to add the video by modifying the HTML code, from the Insert HTML button of sharepoint, but that is not really user friendly.
Preview, on a blog post :
image

 

New youtube embedded format ?

I modified one of the method of Kirk Evans in order to accept the new youtube embedded video format. The new embedded video format looks like this :

New youtube embedded code for video (<iframe) :

image

Old youtube embedded code for video (object) :

image

So to update Kirk Evans code, replace the last method by :

   1: private string ReplaceEmbedsWithTokens(string body)
   2:         {
   3:             //VARS
   4:                 string returnString = null;
   5:                 //Old version of youtube embedded
   6:                 Regex rx = new Regex("(&lt;object).*?(&lt;embed src=&quot;)(?<src>.*?)(&quot;)(.*?)(&lt;/object&gt;)");
   7:
   8:             //CLEANING from a text editor
   9:             body = body.Replace("nr", " ");
  10:             body = body.Replace("rn", " ");
  11:
  12:             if (rx.IsMatch(body) == false)
  13:             {
  14:                 //New version of youtube embedded
  15:                 rx = new Regex("(&lt;iframe).*?(src=&quot;)(?<src>.*?)(&quot;)(.*?)(&lt;/iframe&gt;)");
  16:                 returnString = rx.Replace(body, "[[BLOGVIDEO: ${src}]]");
  17:                 returnString = returnString.Replace("embed", "v");
  18:             }
  19:             else
  20:             {
  21:                 //Old version of youtube embedded
  22:                 returnString = rx.Replace(body, "[[BLOGVIDEO: ${src}]]");
  23:             }
  24:
  25:
  26:             return returnString;
  27:         }

It also fix a bug : when you paste the embedded code in a word document in order to save it, and then you paste it in a blog, it won’t work properly.

Enjoy, and thanks again Kirk Evans

- Advertisement -

1 COMMENT

  1. After study a number of of the blog posts on your website now, and I actually like your means of blogging. I bookmarked it to my bookmark web site checklist and can be checking again soon. Pls take a look at my website as nicely and let me know what you think.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CONNECT FOR MORE CONTENT

DO NOT MISS THOSE ARTICLES

Recent Comments