[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

jeudi 9 février 2012

What is that ?

Based on this excellent tutorial from kirk Evans :
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 :


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) :
Old youtube embedded code for video (object) :

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;)");
   8:             //CLEANING from a text editor
   9:             body = body.Replace("\n\r", " ");
  10:             body = body.Replace("\r\n", " ");
  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:             }
  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

Aucun commentaire:



Jeff ANGAMA, is a business / technique consultant around SharePoint 2013 technologies. - More Infos Here -

Rechercher dans ce blog

Follow by Email

Where Users are from ?