Friday, December 30, 2016

Hide components located on the SharePoint Online master page, oslo.master

In order to hide various components located on the oslo.master master page of SharePoint Online site, a brutally simple solution is to insert a Script Editor web part on the web page and add one or more of the following CSS elements to it:

<style>

     .ms-srch-sb {display:none;}

     .ms-core-pageTitle {display:none;}

     #pageContentTitle { display:none;}

     #titlerow { display:none;}

</style>

Just a quick warning, placing all of these CSS elements on the web page is going to turn the web page into a blank page (that is, if you don't have any content on it) so feel free to remove any of those CSS elements listed above if you want that component to be displayed.

Here is a key that explain which element removes which control:

.ms-srch-sb {display:none;} - removes just the Search control
.ms-core-pageTitle {display:none;} - removes just the Page Title
#pageContentTitle { display:none;} - removes just the Site Title
#titlerow { display:none;} - removes the Site Logo, Site Title, and Search Control

Friday, November 4, 2016

RequiredExpressionValidator expression to limit the number of characters entered in a textbox

For the ASP.NET project that I'm currently working on, I wanted to limit the number of characters that could be entered into a specific textbox control to a maximum of 25 characters (NOTE: since this was a required field so I also wanted them to at least enter 1 character); however, in this particular instance, I wanted to allow the user to be able to enter any kind of special character.  To provide this capability, I used the following value for my ValidationExpression:

^.{1,25}$

Now, if I did want to limit the type of characters entered to be only alpha-numeric and empty spaces, I used the following:

^[a-zA-Z0-9 ]{1,25}$


Tuesday, June 28, 2016

Obtain a list of SharePoint subsites using Javascript CSOM

Here is some code that you can utilize for obtaining a list of SharePoint subsites that the given user has access to:

<div id="selectsubwebs"></div>

<script type="text/javascript">
   var subsites = null;
   var web = null;
   var context = null;
   var subweb = null;
   var renderedHTML = "";
   var scriptbase = "https://rootSiteUrl/_layouts/15/";

   $.getScript(scriptbase + "SP.Runtime.js", function() {
      $.getScript(scriptbase + "SP.js", function() {
         $.getScript(scriptbase + "SP.RequestExecutor.js", getSubWebs);
      });
   });

   function getSubWebs(){
      context = SP.ClientContext.get_current();
      web = context.get_web();
      context.load(web);
      context.executeQueryAsync(onGetWebSuccess, onGetWebFail);
   }

   function onGetWebSuccess(sender, args) {
      //subsites = web.get_webs();  //Complete list of subsites
      subsites = web.getSubwebsForCurrentUser(null);
      context.load(webCollection);
      context.executeQueryAsync(onGetSubwebsSuccess, onGetSubwebsFail);
   }

   function onGetSubwebsSuccess(sender, args) {
      renderedHTML = renderedHTML + "<table id='table_id' class='display'><thead><tr><th>Team Site Title</th></tr></thead><tbody>";
      var webEnumerator = subsites.getEnumerator();
      while (webEnumerator.moveNext()){
         subweb = webEnumerator.get_current();
         renderedHTML = renderedHTML + "<tr><td><a href='" + subweb.get_url() + "' target='_blank'>" + subweb.get_title() + "</a></td></tr>";
      }
      renderedHTML = renderedHTML + "</tbody></table>";

      document.getElementById("selectsubwebs").innerHTML = renderedHTML;

   }
   function onGetSubwebsFail(sender, args){
      alert("Request to retrieve subwebs failed. Error: " + args.get_message())
   }

   function onGetWebFail(sender, args){
      alert("Request to retrieve subwebs failed. Error: " + args.get_message())
   }
</script>