11/28/2015

SharePoint Content Type Inheritance

This article applies to SharePoint 2010, 2013 and 2016.

If you have worked around SharePoint for a while then you have heard the phrase "Everything is a list…". If everything is a list then everything should be an "item", right? Turns out that that is almost a fact. With the exception of only a handful of Content Types, they all inherit from"Item". In the end everything inherits from a base type named "System". The listing below is from a 2013 publishing site with a few extra features enabled to find as many Content Types as possible. The 2016 list is very similar, but is missing some of the Business Intelligence content types (Excel Services?).

A few examples:

  • Task <- Item <- System
  • Document <- Item <- System
  • Video <- System Media Collection <- Document Set <- Document Collection Folder <- Folder <- Item <- System

What does not inherit from Item?

  • Common Indicator Columns <- System  (hidden)
  • And the types that inherit from it:
    • Excel based Status Indicator <- Common Indicator Columns <- System
    • Fixed Value based Status Indicator <- Common Indicator Columns <- System
    • SharePoint List based Status Indicator <- Common Indicator Columns <- System
    • SQL Server Analysis Services based Status Indicator <- Common Indicator Columns <- System

 

    PowerShell to the rescue… again.

    To dump the hierarchy of Content Types I wrote a little PowerShell script that uses a recursive function. Just edit the URL to your site and you can get your list of Content Types.

    If you wanted to see the inheritance pattern another way, add the ID of the Content Type to your output, or just do a test like the following and note the pattern in the IDs:

      $web.ContentTypes | sort id | Select id, name

     

    The PowerShell script:

    function Get-CTypeParent ($ctype, $TTNstr)
    {
      if ($ctype.name -NE "System") {
       $TTNstr = $TTNstr + " <- " + $ctype.parent.name;
       $TTNstr = Get-CTypeParent $ctype.parent $TTNstr 
       }
      return $TTNstr;
    }
    
    $site = Get-SPSite http://yourserver/sites/yourSite
    $web = $site.RootWeb
    
    $web.ContentTypes | sort Group, Name | 
      group Group | 
        foreach { $_.Group  | 
                         foreach 
                           -Begin {"`n" + $_.Name} 
                           -Process { $str="  " + $_.Name ;  Get-CTypeParent $_ $str } 
                }
    

     

    The list of Content Types and their family history!

    This list is from SharePoint 2013. The 2016 list is very similar, but is missing some of the Business Intelligence content types (Excel Services?).

    _Hidden
      Administrative Task <- Task <- Item <- System
      Approval Workflow Task (en-US) <- SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      Collect Feedback Workflow Task (en-US) <- SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      Collect Signatures Workflow Task (en-US) <- SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      Common Indicator Columns <- System
      Design File <- Document <- Item <- System
      Device Channel <- Item <- System
      Device Channel Mappings <- Document <- Item <- System
      Display Template <- Document <- Item <- System
      Display Template Code <- Display Template <- Document <- Item <- System
      Document Collection Folder <- Folder <- Item <- System
      DomainGroup <- Item <- System
      Health Analyzer Report <- Item <- System
      Health Analyzer Rule Definition <- Item <- System
      InfoPath Form Template <- Document <- Item <- System
      Office Data Connection File <- Document <- Item <- System
      Page Output Cache <- Item <- System
      PerformancePoint Base <- Item <- System
      PerformancePoint Monitoring Document Type <- Document <- Item <- System
      Person <- Item <- System
      Project Policy <- Item <- System
      Published Link <- Item <- System
      Publishing Approval Workflow Task (en-US) <- SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      Reusable HTML <- Item <- System
      Reusable Text <- Item <- System
      RootOfList <- Folder <- Item <- System
      Rule <- Item <- System
      SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      SharePointGroup <- Item <- System
      Signatures Workflow Task Deprecated <- SharePoint Server Workflow Task <- Workflow Task <- Task <- Item <- System
      System
      System Master Page <- Document <- Item <- System
      System Media Collection <- Document Set <- Document Collection Folder <- Folder <- Item <- System
      System Page <- Document <- Item <- System
      System Page Layout <- Document <- Item <- System
      Translation Package <- Document <- Item <- System
      Translation Status <- Document <- Item <- System
      Universal Data Connection File <- Document <- Item <- System
      User Workflow Document <- Document <- Item <- System
      Workflow History <- Item <- System
      Workflow Task <- Task <- Item <- System
      WorkflowServiceDefinition <- Item <- System
      WorkflowServiceSubscription <- Item <- Systemvi
     
    Business Intelligence
      Excel based Status Indicator <- Common Indicator Columns <- System
      Fixed Value based Status Indicator <- Common Indicator Columns <- System
      Report <- Document <- Item <- System
      Report Document <- Document <- Item <- System
      SharePoint List based Status Indicator <- Common Indicator Columns <- System
      SQL Server Analysis Services based Status Indicator <- Common Indicator Columns <- System
      Web Part Page with Status List <- Document <- Item <- System
     
    Community Content Types
      Category <- Item <- System
      Community Member <- Site Membership <- Item <- System
      Site Membership <- Item <- System
     
    Digital Asset Content Types
      Audio <- Rich Media Asset <- Document <- Item <- System
      Image <- Rich Media Asset <- Document <- Item <- System
      Rich Media Asset <- Document <- Item <- System
      Video <- System Media Collection <- Document Set <- Document Collection Folder <- Folder <- Item <- System
      Video Rendition <- Rich Media Asset <- Document <- Item <- System
     
    Display Template Content Types
      Control Display Template <- Display Template <- Document <- Item <- System
      Filter Display Template <- Display Template <- Document <- Item <- System
      Group Display Template <- Display Template <- Document <- Item <- System
      Item Display Template <- Display Template <- Document <- Item <- System
      JavaScript Display Template <- Document <- Item <- System
     
    Document Content Types
      Basic Page <- Document <- Item <- System
      Document <- Item <- System
      Dublin Core Columns <- Document <- Item <- System
      Form <- Document <- Item <- System
      Link to a Document <- Document <- Item <- System
      List View Style <- Document <- Item <- System
      Master Page <- Document <- Item <- System
      Master Page Preview <- Document <- Item <- System
      Picture <- Document <- Item <- System
      Web Part Page <- Basic Page <- Document <- Item <- System
      Wiki Page <- Document <- Item <- System
     
    Document Set Content Types
      Document Set <- Document Collection Folder <- Folder <- Item <- System
     
    Folder Content Types
      Discussion <- Folder <- Item <- System
      Folder <- Item <- System
      Summary Task <- Folder <- Item <- System
     
    Group Work Content Types
      Circulation <- Item <- System
      Holiday <- Item <- System
      New Word <- Item <- System
      Official Notice <- Item <- System
      Phone Call Memo <- Item <- System
      Resource <- Item <- System
      Resource Group <- Item <- System
      Timecard <- Item <- System
      Users <- Item <- System
      What's New Notification <- Item <- System
     
    List Content Types
      Announcement <- Item <- System
      Comment <- Item <- System
      Contact <- Item <- System
      East Asia Contact <- Item <- System
      Event <- Item <- System
      Issue <- Item <- System
      Item <- System
      Link <- Item <- System
      Message <- Item <- System
      Post <- Item <- System
      Reservations <- Event <- Item <- System
      Schedule <- Event <- Item <- System
      Schedule and Reservations <- Event <- Item <- System
      Task <- Item <- System
      Workflow Task (SharePoint 2013) <- Task <- Item <- System
     
    Page Layout Content Types
      Article Page <- Page <- System Page <- Document <- Item <- System
      Catalog-Item Reuse <- Page <- System Page <- Document <- Item <- System
      Enterprise Wiki Page <- Page <- System Page <- Document <- Item <- System
      Error Page <- Page <- System Page <- Document <- Item <- System
      Project Page <- Enterprise Wiki Page <- Page <- System Page <- Document <- Item <- System
      Redirect Page <- Page <- System Page <- Document <- Item <- System
      Welcome Page <- Page <- System Page <- Document <- Item <- System
     
    PerformancePoint
      PerformancePoint Dashboard <- PerformancePoint Base <- Item <- System
      PerformancePoint Data Source <- PerformancePoint Monitoring Document Type <- Document <- Item <- System
      PerformancePoint Filter <- PerformancePoint Base <- Item <- System
      PerformancePoint Indicator <- PerformancePoint Base <- Item <- System
      PerformancePoint KPI <- PerformancePoint Base <- Item <- System
      PerformancePoint Report <- PerformancePoint Base <- Item <- System
      PerformancePoint Scorecard <- PerformancePoint Base <- Item <- System
     
      
    Publishing Content Types
      ASP NET Master Page <- System Master Page <- Document <- Item <- System
      Html Master Page <- ASP NET Master Page <- System Master Page <- Document <- Item <- System
      Html Page Layout <- Page Layout <- System Page Layout <- Document <- Item <- System
      Page <- System Page <- Document <- Item <- System
      Page Layout <- System Page Layout <- Document <- Item <- System
     
    Special Content Types
      Unknown Document Type <- Document <- Item <- System

     

    The List Sorted By Ancestor

    Change the last line of the script to the following and you can see another pattern in the inheritance.

    $web.contenttypes | sort group, name | group group | foreach { $_.Group  | foreach -begin {"`n" + $_.Name} -process { $str="  " + $_.name ;  Get-CTypeParent $_ $str } }

    System ->   Item
    System -> Item ->   Announcement
    System -> Item ->   Circulation
    System -> Item ->   Comment
    System -> Item ->   Contact
    System -> Item ->   Device Channel
    System -> Item ->   Document
    System -> Item ->   DomainGroup
    System -> Item ->   East Asia Contact
    System -> Item ->   Event
    System -> Item ->   Folder
    System -> Item ->   Health Analyzer Report
    System -> Item ->   Health Analyzer Rule Definition
    System -> Item ->   Holiday
    System -> Item ->   Issue
    System -> Item ->   Link
    System -> Item ->   Message
    System -> Item ->   New Word
    System -> Item ->   Official Notice
    System -> Item ->   Page Output Cache
    System -> Item ->   PerformancePoint Base
    System -> Item ->   Person
    System -> Item ->   Phone Call Memo
    System -> Item ->   Post
    System -> Item ->   Published Link
    System -> Item ->   Resource
    System -> Item ->   Resource Group
    System -> Item ->   Reusable HTML
    System -> Item ->   Reusable Text
    System -> Item ->   Rule
    System -> Item ->   SharePointGroup
    System -> Item ->   Task
    System -> Item ->   Timecard
    System -> Item ->   Users
    System -> Item ->   What's New Notification
    System -> Item ->   Workflow History
    System -> Item ->   WorkflowServiceDefinition
    System -> Item ->   WorkflowServiceSubscription
    System -> Item -> Document ->   Basic Page
    System -> Item -> Document ->   Design File
    System -> Item -> Document ->   Device Channel Mappings
    System -> Item -> Document ->   Display Template
    System -> Item -> Document ->   Dublin Core Columns
    System -> Item -> Document ->   Form
    System -> Item -> Document ->   InfoPath Form Template
    System -> Item -> Document ->   JavaScript Display Template
    System -> Item -> Document ->   Link to a Document
    System -> Item -> Document ->   List View Style
    System -> Item -> Document ->   Master Page
    System -> Item -> Document ->   Master Page Preview
    System -> Item -> Document ->   Office Data Connection File
    System -> Item -> Document ->   PerformancePoint Monitoring Document Type
    System -> Item -> Document ->   Picture
    System -> Item -> Document ->   Report Document
    System -> Item -> Document ->   Rich Media Asset
    System -> Item -> Document ->   System Master Page
    System -> Item -> Document ->   System Page
    System -> Item -> Document ->   System Page Layout
    System -> Item -> Document ->   Translation Package
    System -> Item -> Document ->   Translation Status
    System -> Item -> Document ->   Universal Data Connection File
    System -> Item -> Document ->   Unknown Document Type
    System -> Item -> Document ->   User Workflow Document
    System -> Item -> Document ->   Wiki Page
    System -> Item -> Document -> Basic Page ->   Web Part Page
    System -> Item -> Document -> Display Template ->   Control Display Template
    System -> Item -> Document -> Display Template ->   Display Template Code
    System -> Item -> Document -> Display Template ->   Filter Display Template
    System -> Item -> Document -> Display Template ->   Group Display Template
    System -> Item -> Document -> Display Template ->   Item Display Template
    System -> Item -> Document -> PerformancePoint Monitoring Document Type ->   PerformancePoint Data Source
    System -> Item -> Document -> Rich Media Asset ->   Audio
    System -> Item -> Document -> Rich Media Asset ->   Image
    System -> Item -> Document -> Rich Media Asset ->   Video Rendition
    System -> Item -> Document -> System Master Page ->   ASP NET Master Page
    System -> Item -> Document -> System Master Page -> ASP NET Master Page ->   Html Master Page
    System -> Item -> Document -> System Page ->   Page
    System -> Item -> Document -> System Page -> Page ->   Article Page
    System -> Item -> Document -> System Page -> Page ->   Catalog-Item Reuse
    System -> Item -> Document -> System Page -> Page ->   Enterprise Wiki Page
    System -> Item -> Document -> System Page -> Page ->   Error Page
    System -> Item -> Document -> System Page -> Page ->   Redirect Page
    System -> Item -> Document -> System Page -> Page ->   Welcome Page
    System -> Item -> Document -> System Page -> Page -> Enterprise Wiki Page ->   Project Page
    System -> Item -> Document -> System Page Layout ->   Page Layout
    System -> Item -> Document -> System Page Layout -> Page Layout ->   Html Page Layout
    System -> Item -> Event ->   Reservations
    System -> Item -> Event ->   Schedule
    System -> Item -> Event ->   Schedule and Reservations
    System -> Item -> Folder ->   Discussion
    System -> Item -> Folder ->   Document Collection Folder
    System -> Item -> Folder ->   RootOfList
    System -> Item -> Folder ->   Summary Task
    System -> Item -> Folder -> Document Collection Folder ->   Document Set
    System -> Item -> Folder -> Document Collection Folder -> Document Set ->   System Media Collection
    System -> Item -> Folder -> Document Collection Folder -> Document Set -> System Media Collection ->   Video
    System -> Item -> PerformancePoint Base ->   PerformancePoint Dashboard
    System -> Item -> PerformancePoint Base ->   PerformancePoint Filter
    System -> Item -> PerformancePoint Base ->   PerformancePoint Indicator
    System -> Item -> PerformancePoint Base ->   PerformancePoint KPI
    System -> Item -> PerformancePoint Base ->   PerformancePoint Report
    System -> Item -> PerformancePoint Base ->   PerformancePoint Scorecard
    System -> Item -> Task ->   Administrative Task
    System -> Item -> Task ->   Workflow Task
    System -> Item -> Task ->   Workflow Task (SharePoint 2013)
    System -> Item -> Task -> Workflow Task ->   PSWApprovalTask
    System -> Item -> Task -> Workflow Task ->   SharePoint Server Workflow Task
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Approval Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Collect Feedback Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Collect Signatures Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Publishing Approval Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Signatures Workflow Task Deprecated

     


     

    System ->   Item
    System -> Item ->   Announcement
    System -> Item ->   Circulation
    System -> Item ->   Comment
    System -> Item ->   Contact
    System -> Item ->   Device Channel
    System -> Item ->   Document
    System -> Item ->   DomainGroup
    System -> Item ->   East Asia Contact
    System -> Item ->   Event
    System -> Item ->   Folder
    System -> Item ->   Health Analyzer Report
    System -> Item ->   Health Analyzer Rule Definition
    System -> Item ->   Holiday
    System -> Item ->   Issue
    System -> Item ->   Link
    System -> Item ->   Message
    System -> Item ->   New Word
    System -> Item ->   Official Notice
    System -> Item ->   Page Output Cache
    System -> Item ->   PerformancePoint Base
    System -> Item ->   Person
    System -> Item ->   Phone Call Memo
    System -> Item ->   Post
    System -> Item ->   Published Link
    System -> Item ->   Resource
    System -> Item ->   Resource Group
    System -> Item ->   Reusable HTML
    System -> Item ->   Reusable Text
    System -> Item ->   Rule
    System -> Item ->   SharePointGroup
    System -> Item ->   Task
    System -> Item ->   Timecard
    System -> Item ->   Users
    System -> Item ->   What's New Notification
    System -> Item ->   Workflow History
    System -> Item ->   WorkflowServiceDefinition
    System -> Item ->   WorkflowServiceSubscription
    System -> Item -> Document ->   Basic Page
    System -> Item -> Document ->   Design File
    System -> Item -> Document ->   Device Channel Mappings
    System -> Item -> Document ->   Display Template
    System -> Item -> Document ->   Dublin Core Columns
    System -> Item -> Document ->   Form
    System -> Item -> Document ->   InfoPath Form Template
    System -> Item -> Document ->   JavaScript Display Template
    System -> Item -> Document ->   Link to a Document
    System -> Item -> Document ->   List View Style
    System -> Item -> Document ->   Master Page
    System -> Item -> Document ->   Master Page Preview
    System -> Item -> Document ->   Office Data Connection File
    System -> Item -> Document ->   PerformancePoint Monitoring Document Type
    System -> Item -> Document ->   Picture
    System -> Item -> Document ->   Report Document
    System -> Item -> Document ->   Rich Media Asset
    System -> Item -> Document ->   System Master Page
    System -> Item -> Document ->   System Page
    System -> Item -> Document ->   System Page Layout
    System -> Item -> Document ->   Translation Package
    System -> Item -> Document ->   Translation Status
    System -> Item -> Document ->   Universal Data Connection File
    System -> Item -> Document ->   Unknown Document Type
    System -> Item -> Document ->   User Workflow Document
    System -> Item -> Document ->   Wiki Page
    System -> Item -> Document -> Basic Page ->   Web Part Page
    System -> Item -> Document -> Display Template ->   Control Display Template
    System -> Item -> Document -> Display Template ->   Display Template Code
    System -> Item -> Document -> Display Template ->   Filter Display Template
    System -> Item -> Document -> Display Template ->   Group Display Template
    System -> Item -> Document -> Display Template ->   Item Display Template
    System -> Item -> Document -> PerformancePoint Monitoring Document Type ->   PerformancePoint Data Source
    System -> Item -> Document -> Rich Media Asset ->   Audio
    System -> Item -> Document -> Rich Media Asset ->   Image
    System -> Item -> Document -> Rich Media Asset ->   Video Rendition
    System -> Item -> Document -> System Master Page ->   ASP NET Master Page
    System -> Item -> Document -> System Master Page -> ASP NET Master Page ->   Html Master Page
    System -> Item -> Document -> System Page ->   Page
    System -> Item -> Document -> System Page -> Page ->   Article Page
    System -> Item -> Document -> System Page -> Page ->   Catalog-Item Reuse
    System -> Item -> Document -> System Page -> Page ->   Enterprise Wiki Page
    System -> Item -> Document -> System Page -> Page ->   Error Page
    System -> Item -> Document -> System Page -> Page ->   Redirect Page
    System -> Item -> Document -> System Page -> Page ->   Welcome Page
    System -> Item -> Document -> System Page -> Page -> Enterprise Wiki Page ->   Project Page
    System -> Item -> Document -> System Page Layout ->   Page Layout
    System -> Item -> Document -> System Page Layout -> Page Layout ->   Html Page Layout
    System -> Item -> Event ->   Reservations
    System -> Item -> Event ->   Schedule
    System -> Item -> Event ->   Schedule and Reservations
    System -> Item -> Folder ->   Discussion
    System -> Item -> Folder ->   Document Collection Folder
    System -> Item -> Folder ->   RootOfList
    System -> Item -> Folder ->   Summary Task
    System -> Item -> Folder -> Document Collection Folder ->   Document Set
    System -> Item -> Folder -> Document Collection Folder -> Document Set ->   System Media Collection
    System -> Item -> Folder -> Document Collection Folder -> Document Set -> System Media Collection ->   Video
    System -> Item -> PerformancePoint Base ->   PerformancePoint Dashboard
    System -> Item -> PerformancePoint Base ->   PerformancePoint Filter
    System -> Item -> PerformancePoint Base ->   PerformancePoint Indicator
    System -> Item -> PerformancePoint Base ->   PerformancePoint KPI
    System -> Item -> PerformancePoint Base ->   PerformancePoint Report
    System -> Item -> PerformancePoint Base ->   PerformancePoint Scorecard
    System -> Item -> Task ->   Administrative Task
    System -> Item -> Task ->   Workflow Task
    System -> Item -> Task ->   Workflow Task (SharePoint 2013)
    System -> Item -> Task -> Workflow Task ->   PSWApprovalTask
    System -> Item -> Task -> Workflow Task ->   SharePoint Server Workflow Task
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Approval Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Collect Feedback Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Collect Signatures Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Publishing Approval Workflow Task (en-US)
    System -> Item -> Task -> Workflow Task -> SharePoint Server Workflow Task ->   Signatures Workflow Task Deprecated

     

     

     

     

     

    11/23/2015

    SharePoint 2013: Hide JSLink from Team Members

    This article applies to SharePoint Online, SharePoint 2013 and 2016.

     

    Let's start with a couple "did you knows"…

    Did you know:

    • All users with Edit and Contribute permission levels can edit the home page of your site?
    • The same users can edit or delete any page in the Site Pages library.?
    • They can also edit the web parts on that page? And use advanced options like JS Link?

    As part of your SharePoint governance or best practices you may want to limit who can use some of the more advanced customization features of SharePoint 2013 and 2016. JS Link, is after all, JavaScript programming and it can cause issues for daily support and the upgrade to future versions of SharePoint.

    Before we get into locking down just JS Link, let's address the "did you knows". You may want to think about changing the permissions of Site Pages, Site Assets and a few other libraries to read only for all users except for Site Owners. Those libraries really should not be open for all to edit.

     

    About JS Link

    JS Link is a really cool technology introduced with SharePoint 2013 to let us customize web parts, views and list forms without "un-ghosting" pages using SharePoint Designer. It lets us create a JavaScript text file, store it in a library, and then link it to a web part or a form. If you are a developer, you can also use JS Link with Site Columns and Site Content Types. One of the benefits of JS Link is that the customization file can be created once, stored in a library and then be linked into many web parts and forms. When you need a change in the future, you only need to edit a single JavaScript file and not dozens or hundreds of web parts.

    For web parts, JS Link is added in the Miscellaneous section of the web part properties panel.

    image

     

    Hiding JS Link

    As SharePoint does not have a "switch" where we can just turn off the use of JS Link, we will need to come up with a CSS or JavaScript solution. If you add the following CSS to your master page (lots of ways to do this) then the JS Link box will be hidden.

    <style type="text/css">
      input[id$="_JSLink_EDITOR"] {
        display:none;
      }
      label[for$="_JSLink_EDITOR"] {
        display:none;
      }
    </style>
    

     

    While we are at it, you may also want to hide the XSL Link option too:

    <style type="text/css">
      input[id$="_JSLink_EDITOR"] {
        display:none;
      }
      label[for$="_JSLink_EDITOR"] {
        display:none;
      }
      input[id$="_XslLink_EDITOR"] {
        display:none;
      }
      label[for$="_XslLink_EDITOR"] {
        display:none;
      }
    </style>
    

     

    But what about the Site Owner?

    If you want some users to still be able to edit the JS Link and XSL Link options then we can give those back using a SharePoint Security Trimmed Control. You just need to pick a permission that is unique that that group of users such as Add and Customize Pages. In the example below we take away JS Link from all users, and then give it back to select users.

    <style type="text/css">
      input[id$="_JSLink_EDITOR"] {
        display:none;
      }
      label[for$="_JSLink_EDITOR"] {
        display:none;
      }
      input[id$="_XslLink_EDITOR"] {
        display:none;
      }
      label[for$="_XslLink_EDITOR"] {
        display:none;
      }
    </style>
    <Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="AddAndCustomizePages"> <!-- Let owners and designers see the JSLink options --> <style type="text/css"> input[id$="_JSLink_EDITOR"] { display:inline; } label[for$="_JSLink_EDITOR"] { display:inline; } input[id$="_XslLink_EDITOR"] { display:inline; } label[for$="_XslLink_EDITOR"] { display:inline; } </style> </SharePoint:SPSecurityTrimmedControl>

     

    .

    11/17/2015

    PowerShell Get-Date vs. [DateTime]

     

    The Cincinnati PowerShell User Group (@CincyPowershell) opens each meeting with a review of a cmdlet. Tonight is was Get-Date's turn. Many of the examples were done with both Get-Date and [datetime], with one example showing that only [datetime] supports the IsLeapYear() method. This got me to thinking… (sometimes a painful thing…) and the light bulb lit up over my head. Get-Date returns an instance of the System.DateTime class, i.e. an object, while [datetime] is a reference to the class and provides easy access to the class's static methods.

     

    System.DateTime

    To be precise, [datetime] is really [System.DateTime], but System is the default name space and PowerShell is not case sensitive (most of the time). And to be precise, Get-Date with no options is the same as[System.DateTime]::Now.

    What's with the two colons? They are PowerShell's way to call a static method on a class. So going back to the IsLeapYear() question, it is a static method of the DateTime class. To access it we write [System.DateTime]::IsLeapYear(2016).

     

    Get-Date

    Get-Date is a cmdlet with many options, but the default option is to return the current date and time. I.e. [System.DateTime]::Now.

    The class that an object was created from is also called it's type. So what's the "type" of a date?

    image

     

    Instances / Objects

    If Get-Date returns an instance, how could I do that with [DateTime]? Two ways, use one of the static methods like .Now or .Today, or create a new object using the New-Object cmdlet.

    Using the static methods:

    $d = [System.DateTime]::Now    (or just [DateTime].Now)

    $d = [System.DateTime]::Today  (or just [DateTime].Today)

    Using New-Object:

    $d = New-Object System.DateTime    (or just DateTime)

    The unique aspect of using New-Object with DateTime is that you get back an object with default values for year, month, day, etc. and not today's date. The actual result is "Monday, January 01, 0001 12:00:00 AM".

    image

    If you want to create a particular date or time, use one of the class's constructors. (See the DateTime Structure link at the end of the article for details.)

    image

    There's a nice write up about classes, instances, statics here from Don Jones.

     

    And just for fun… and only in PowerShell 5.0

    Who needs [System.DateTime]?  Just call the static methods off of any DateTime object! The following all produce the same result, keeping in mind that Get-Date adds the additional overhead of retrieving the current date, and then ignoring it.

    (Get-Date)::IsLeapYear(2016)

    $d = Get-Date
    $d::IsLeapYear(2016)

    $d = [System.DateTime]::Now
    $d::IsLeapYear(2016)

     

    What about PowerShell 3.0?

    The examples for 5.0 do not work with 3.0. We have to ask for the "class", i.e. it's Type.

    (Get-Date).GetType()::IsLeapYear(2016)

    $d = Get-Date
    $d.GetType()::IsLeapYear(2016)

    $d = [System.DateTime]::Now
    $d.GetType()::IsLeapYear(2016)

     

    What about PowerShell 4.0?

    Beats me! (Don't have a copy in front of me right now.)

     

    Discover the Static Methods and Properties of an Object

    Get-Member has a –Static parameter to display the static methods and properties of an object:

    Get-Date | Get-Member -Static

    image

     

    More Fun With Static Methods

    Most .Net classes are not exposed in PowerShell as cmdlets.

    For example, you might need a new GUID…

    [System.Guid]::NewGuid()   will return a new GUID object.

    [System.Guid]::NewGuid().toString()   will return a new GUID as a string.

    image

    How about some Math?

    Need the value of PI?

    [System.,Math]::PI  (or just [Math]::PI)  It's about 3.14159265358979 according to PowerShell and .Net.

    How about the square root of 2?

    [Math]::Sqrt(2)  (Let's see… I think it's about 1.4142135623731.)

    And of course, the Sine of 45 degrees:

    [Math]::sin(0.785398163397448)  (in Radians of course) Oh, about 0.707106781186547.

    And doing a little converting from degrees to Radians:

    [Math]::sin( [Math]::pi/180*45 )

    For more of what the Math class can do, see the Math link at the end of the article. Or, wait for it, use PowerShell:

    [Math] | Get-Member  -Static

     

    Bottom line… if the C# guys can do it, then so can you!

     

    So now you know… 2016 is a leap year!  And at least a dozen different ways!

     

    (and a quick 5 minute article took over an hour…)

     

    References:

    Using Static Classes and Methods
    https://technet.microsoft.com/en-us/library/dd347632.aspx

    How to Create an Object in PowerShell
    http://blogs.msdn.com/b/powershell/archive/2009/03/11/how-to-create-an-object-in-powershell.aspx

    DateTime Structure (All of the constructors, methods and properties of DateTime)
    https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx

    A nice write up on class, object, instance and static by Don Jones:
    http://powershell.org/wp/2014/09/08/powershell-v5-class-support/

    System.Math Class
    https://msdn.microsoft.com/en-us/library/system.math(v=vs.110).aspx

     

    .

    11/16/2015

    Add a Crumb Trail to SharePoint 2013

     

    Solution #1: Restore the SharePoint 2010 Navigate Up button

    See here: http://techtrainingnotes.blogspot.com/2014/06/sharepoint-2013-restoring-2010-navigate.html

    [image%255B21%255D.png]

     

    Solution 2: Add an always displayed site crumb trail

    If you only need a crumb trail to be able to navigate back up to a parent site then we can add a site map control to the master page like this:

    <span style="font-size:8pt;">
      <asp:SiteMapPath id="ContentMap2" 
           SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" 
           runat="server"/> 
    </span>

    Edit your master page, search for "</h1>" and add the HTML above just below the "</h1>".

    The result will look like this:

    image

     

    Solution 3: Add an always displayed site and folder crumb trail

    See the link below for a nice solution that reuses the SharePoint:ListSiteMapPath control from the SharePoint 2010 Navigate Up control and reformats it into a single line.

    http://www.broculos.net/2013/12/sharepoint-2013-branding-show-folder.html

    The result looks like this:

    image

    Notes:

    • The author of that article was working with a Publishing feature Design Manager master page and wrapped the control inside of an HTML comment block. (<!--   -->) You will not need this for a non-publishing site master paged edited in SharePoint Designer.
    • The article's sample CSS code needs to be placed inside of a linked CSS file or inside of style tags. <style type="text/css">  ,,,  </style>
    • To get the crumb trail display exactly where I wanted it I added it just after the "</h1>" tag in the master page and added this to the article's CSS:
        .my-breadcrumb {
           margin-top:0px;
           margin-left:3px;
           font-size:8pt;
        }

     

    Other options

    Here's a project that adds a folder crumb trail to library web parts using JS Link: SharePoint 2013: Folder Navigation/Breadcrumb
    http://social.technet.microsoft.com/wiki/contents/articles/19713.sharepoint-2013-folder-navigationbreadcrumb.aspx and here: http://ranaictiu-technicalblog.blogspot.com/2013/07/sharepoint-2013-folder-navigation-for.html

    The only disadvantage to this solution is that you need to make a change to every list/library/view web part.

     

    .

    11/14/2015

    Sorting Hashtables and SharePoint Properties Lists with PowerShell

     

    Sometimes the obvious just does not work… I was doing some work with SharePoint publishing sites, trying to find some of the data in the SPWeb AllProperties property. AllProperties looks like a collection of Names and Values. Actually it is Hashtable object.

    My first attempt looked like this:

        $psite.AllWebs[0].AllProperties | sort -Property name

    image

    The output was random, not sorted as expected. After too long messing with trial and error, I did a web search and found a TechNet "Windows PowerShell Tip of the Week" article with the answer. Hashtable objects and sort just don't work together. We need to get an enumerator for the hash table and work with that…

       $psite.AllWebs[0].AllProperties.GetEnumerator() | sort -Property name

    image

    That's the output I was looking for!

    If you pipe both of the above to Get-Member you will see that the first just returns a Hashtable object that includes a collection of Keys and a collection of Values. The second one, using GetEnumerator, returns a single DictionaryEntry object (one at a time through the pipeline) with a Key and a Value property. Now we have something to sort on!

    image

    .

    Weird SharePoint Icons = Timeout!


    Have you ever had a SharePoint page "explode"? Odds are something from the server timed out. In the example below the CSS files never got loaded. The links timed out. A simple refresh should fix it. If it does, let your server admins know about the issue.

    BTW, those weird looking icon collections are call image sprites.

    image

     

    If the refresh does not fix the problem, you may have a broken master page. (Have you been playing around with SharePoint Designer?) You can either use SharePoint Designer to select a working master page or edit your site's URL to take you to the Site Settings page and select one there..
    Change:
      http://yourServer/sites/yourSite/Pages/Default.aspx  (or whatever your URL looks like)
    to something like:
      http://yourServer/sites/yourSite/_layouts/settings.aspx  (2013 will redirect and add a "15" to the URL.)

    From that page you can select another master page or make other changes to fix the issue. In some cases you even need to open SharePoint Designer to undo the change you made or to select another master page. For a publishing site click Master Pages in the Look and Feel section of the Site Settings page. If you see the following message then you do have a master page problem.

    image

    In some cases, just clicking OK and selecting the same master page will fix the problem. Otherwise, select Seattle or Oslo and see if that gets your site working again.

    11/08/2015

    Fifty+ SharePoint 2013 Sample Background Images

    The following applies to SharePoint 2013 and SharePoint Online / Office 365.

    Theme Background Images

    When designing a theme for your site you can use a background image for the page. Did you know that SharePoint 2013 includes more than fifty 1024 x 768 sample images? Ten of the sample themes use the first ten of these images. These ten images and forty more can be found at the following URLs:

    https://yourServerDomain/_layouts/15/images/image_bg002.jpg
    or
    https://yourServerDomain/sites/yourSite/_layouts/15/images/image_bg002.jpg

    Replace the “image_bg002.jpg” with the names from the samples below.

     

    Background images used with the sample themes:

    image

     

    Additional Background Images Available:

    image
    image

    image

    image

    image

     

    And a few more interesting images from that folder:

    image

    .

    11/07/2015

    Windows Explorer Search – Learn something new every day…

     

    I was searching through around 400 folders with thousands of files for all of the files that contained "_files" in their names. Should be easy… open Windows Explorer and type in the search box *_files* and wait… but I got back every file as if I had typed "*".

    Is the underline a wildcard?

    Not according to the documentation I can find, and it does not otherwise behave like a wildcard. For example, searching for "f_le" or "*f_le*" did not find anything.

    Is the underline ignored?

    Seems like it. Except… if you include a file type in the search then the underline is treated as an ordinary character or if you use the FileName property.

    Two solutions:

    Add a filetype wild card:   *_file*.*   

    Search using a property name:   filename:*_file*    (but don't add ".*" if you are also looking for folders!)

     

    What about good ole DOS?

    Works exactly as expected.   DIR *_files* /s   .

     

    What about PowerShell

    Also works exactly as expected.   dir -Filter *_files* –Recurse

    I should have started with PowerShell anyway as the next step was to rename these files! Smile

     

    What creates file names that include "_file"?

    Internet Explorer when you use File, Save As, Web Page Complete.

     

    .

    11/04/2015

    The specified module 'Microsoft.Online.SharePoint.PowerShell' was not loaded

     

    When trying to load the SharePoint Online PowerShell module into the ISE or an existing shell you may get the error below. Simple problem with a non-obvious error message… The fix is easy… after installing the SharePoint Online Management Shell, run PowerShell or the ISE as Administrator.

    PS C:\> Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
    Import-Module : The specified module 'Microsoft.Online.SharePoint.PowerShell' was not loaded because no valid 
    module file was found in any module directory.
    At line:1 char:1
    + Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ResourceUnavailable: (Microsoft.Online.SharePoint.PowerShell:String) [Import-Mo 
       dule], FileNotFoundException
        + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    Note to spammers!

    Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.