Posts

Showing posts from June, 2013

SharePoint 2013 - Working with Display Template for Content Search Web Part

Image
To create a custom display template, the best approach is to copy an existing one from Out-Of-Box display templates.  You can try each one and find the one that is closest to what you want to do. All the display templates are in the master page gallery.  To access it, Site Settings -> Master pages and page layouts -> Display Templates The Content Web Parts folder contains the display templates for content search web part and Search folder contains the display templates for the search results web parts. The easiest way to take a look at the display templates is to open the list in windows explorer.  On the ribbon, click on Open with Explorer option. You'll see a lot of html and js files in Content Web Parts folder.  The HTML files are the ones that you'll need to take a look.  The .js files are auto-generated when you add a new HTML file or update an existing one. For every content search web part, you usually have to specify two display template, Control a

Access Term Store Programmatically

To get the term store or term set or term, you need to get the TaxonomySession first.  You also need to reference Microsoft.SharePoint.Taxonomy namespace using (SPSite site = new SPSite ("")) {    TaxonomySession taxonomySession = new TaxonomySession (Site);    //get the default one    TermStore termStore = taxonomySession.DefaultSiteCollectionTermStore;    /* or you can get the one you want by looping through all the term stores      taxonomySession.TermStores    */    Group group = termStore.Groups[ "groupName" ];    TermSet termSet = group.TermSets["TermSetName"];    //you can further looping through all the terms in the term set    TermCollection terms = termSet.Terms    Term term = terms[0]; //For the term that has multiple languages, you can get the label in the specific language by passing in the LCID.    term.GetDefaultLabel(1033); }

SharePoint InputFormTextBox Rich Text Validation

I had some problems validating SharePoint InputFormTextBox with InputFormRequiredFieldValidator.  The problem is that it always shows the InputFormTextBox as invalid even tho I did have some content in the text box.  And if you click the submit button the second time, the validation just doesn't work any more. To get around it, I had to use the ASP.NET custom validator.  I found this way from other blogs online so it's nothing new.  However, there is a key attribut that a lot of blog forgot to mention.  Below is my code snippet. function ValidateMessageBody(source, args) {     try {         //Create Rich TextBox Editor control object          var docEditor = RTE_GetEditorDocument(source.controltovalidate);         if ( null == docEditor)             return ;         var strHtml = docEditor.body.innerText;         if (strHtml == "" ) {             args.IsValid = false ;             return ;         }     } catch (err) { }     args.