Sunday, 17 November 2013

SharePoint 2013:Programatically generate EmbedCode for uploaded Video

In this post I will post a code example to generate a SharePoint embedCode for the uploaded videos , In SharePoint you can add three different types of video files 
  1. Upload video 
  2. Provide link to the video
  3. Using EmbedCode

if you use the third option the field VideoSetEmbedCode will contain the embed iframe of the video  but if you use the first option the Field VideoSetEmbedCode will remain empty , although you can get the embed code any time manually as you play the video.

The question is how to get the EmbedCode Programatically ? let us first check the format of the automatically generated embed code by SharePoint
it's simply Iframe with Src attribute with different set of parameters
  1. Player Url            "/_layouts/15/videoembedplayer.aspx"
  2. Some Parameter like:
    1. Site  : Site ID
    2. Web :Web ID
    3. Folder :Actually this is the current video Item ID not the parent Folder ID (Don't know why it's named as Folder)
    4. img: Thumbnail image of the Video
    5. lowner: if it equals 1 the owner name will be displayed 
    6. lTitle: if it equals  1 the title will be displayed
The question is how to construct this from the VideoItem  the code below do the trick



it first check if the VideoSetEmbedCode is not empty then if it's empty it constructs the EmbedCode in the same manner SharePoint does 

Monday, 11 November 2013

SharePoint Apps Pricing models

The new SharePoint App store got three different Pricing models , when you submit or update you app you can change the pricing model at the last step of the submission , the available pricing models are

  • Free 
I think this model does not require any explanation you post your app for free no revenuee unless some hits to your website (if you are using a provider hosting app model)
  • One Time purchase 
The buyer will pay once and will use the application unlimited in this option you can set trail version support for number of days  and users 

  • Sold as subscription
The user can download and use the app, in perpetuity or until they cancel their subscription, for a recurring monthly fee.



Sunday, 10 November 2013

Retrieve VideoSetEmbedCode using Search API

I've created new asset library in SharePoint , when I upload a new video I have the option to select an embed video , when I try to query the video Item using Search RESTful API The VideoSetEmbedCode is not appearing , below is the troubleshooting steps i did to overcome the problem

  1. Open the Central administration
  2. Click on Manage service Application
  3. Manage Search service Application
  4. Click on Search Schema
  5. Try To search for managed property (no luck)
  6. Try to search for crawled property (no luck)
  7. using the powershell I retrieved the Video Item and it got he property ows_VideoSetEmbedCode so why this crawled property is not appearing in the search schema 
  8. I find out that the Field is hidden so I tried to unhide it using powershell and failed
  9. it turns out that CanToggleHidden is set to false so I used the below code to make it unhidden
  10.  using (SPSite  site=new SPSite("http://sp:2020"))
                {
    
    
                    SPList list = site.RootWeb.Lists["MediaLibrary"];
                    SPField videoField = list.Fields.GetFieldByInternalName("VideoSetEmbedCode");
    
                    Type type = videoField.GetType();
                    MethodInfo mi = type.GetMethod("SetFieldBoolValue", BindingFlags.NonPublic | BindingFlags.Instance);
                    mi.Invoke(videoField, new object[] { "CanToggleHidden", true });
                    videoField.Hidden = false;
                    videoField.Update();
    
                   
               
                }
    
    
    I performed full crawling and now it works I can retrieve the VideoSetEmbedCode using Search API (Restful /KeywordQuery)