Table of Contents Webparts: Set Display Columns

In SharePoint 2013's version of the Table of Contents Web Part, the Display Columns setting in the configuration options has been removed.  The default setting is two columns, which can end up looking out of place on a home page.  This small script allows you to set the display

 
 
 
 
 
5 Star
(4)
1,091 times
Add to favorites
SharePoint
11/17/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • It didn't work
    1 Posts | Last post February 11, 2017
    • I am getting this error;
      You cannot call a method on a null-valued expression.
      At C:\scripts\SP2013SetDisplayColumns.ps1:8 char:1
      + $page.checkout()
      + ~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      Exception calling "GetLimitedWebPartManager" with "2" argument(s):
      "fullOrRelativeUrl"
      At C:\scripts\SP2013SetDisplayColumns.ps1:10 char:1
      + $manager =
      $web.GetLimitedWebPartManager($page.Url,[System.Web.UI.WebControls.We ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : ArgumentException
      
      The property 'displaycolumns' cannot be found on this object. Verify that the
      property exists and can be set.
      At C:\scripts\SP2013SetDisplayColumns.ps1:17 char:1
      + $webpart.displaycolumns = 4
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : PropertyNotFound
      
      You cannot call a method on a null-valued expression.
      At C:\scripts\SP2013SetDisplayColumns.ps1:18 char:1
      + $manager.SaveChanges($webpart)
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      You cannot call a method on a null-valued expression.
      At C:\scripts\SP2013SetDisplayColumns.ps1:19 char:1
      + $page.update()
      + ~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
      You cannot call a method on a null-valued expression.
      At C:\scripts\SP2013SetDisplayColumns.ps1:20 char:1
      + $page.checkin("Checked in through PS")
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
          + FullyQualifiedErrorId : InvokeMethodOnNull
      
  • This doesn't work for me either
    1 Posts | Last post November 08, 2016
    • The script runs with no errors, and when I export the webpart I can see it has set the value to e.g. 4, but the web part's appearance does not change, still only one column. 
  • Does this work for SharePoint 2016?
    1 Posts | Last post August 17, 2016
    • I have run the script and it completes successfully but the changes are not reflected in the page.
      
      Url
      ---
      Pages/CustomerServicePortal.aspx
      http://server/sites/KMP
      Pages/CustomerServicePortal.aspx
      3
      
      I have also added Davids suggestion but still not working.
      
  • Not adding columns
    2 Posts | Last post April 18, 2016
    • I modified the script and it ran successfully with the following output. But it never actually made a change to the page. Any ideas? I also had it set to 7, but its displaying 2?
      
      PS D:\zach> .\SP2013SetDisplayColumns.ps1
      
      Url
      ---
      Pages/default.aspx
      http://dcworks2013/policies
      Pages/default.aspx
      2
    • I had to add "$manager.SaveChanges($webpart)" after setting the number of columns to get it to save the changes.
  • I'm not sur how to specify $pages
    2 Posts | Last post January 19, 2016
    • The full url of where the Web part is, is : http://vshare/sites/IT/Operations/EUC/projects/SitePages/Home.aspx
      So I put $web = get-spweb http://vshare/sites/IT/Operations/EUC/projects (Right?)
      $pages = $webpub.GetPublishingPages(Then what do I put in here?)
      
      
    • Use http://vshare/sites/IT/Operations/EUC/projects/SitePages in $web.  It's the OOB pages library I'm assuming, and then place in the -url like Home.aspx.
      
      It should work then.
  • Thanks.
    1 Posts | Last post November 17, 2014