1

I'm trying to add a tilesviewwebpart to a site page using powershell, and I keep getting an error on this line of code

$PLwebpart = New-Object Microsoft.SharePoint.WebPartPages.TilesViewWebPart 

New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.WebPartPages.TilesViewWebPart. At line:1 char:14 + $PLwebpart = New-Object Microsoft.SharePoint.WebPartPages.TilesViewWebPart+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand

Has anyone ever ran into this problem before?

1 Answer 1

1

This would have worked with other types of webparts, e.g.

$PLwebpart = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart

However, the TilesViewWebPart class is abstract, which means that you cannot instantiate it.

You would have to do something like creating a class library to implement the webpart, and then use the .dll to add an instance of the class you created.

Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TilesWP
{
    public class TilesWP : Microsoft.SharePoint.WebPartPages.TilesViewWebPart
    {
        protected override Microsoft.SharePoint.WebPartPages.TileData[] GetTiles()
        {
            throw new NotImplementedException();
        }
        protected override string ViewTitle
        {
            get { throw new NotImplementedException(); }
        }
    }
}

PowerShell

Add-Type -Path TilesWP.dll
$webpart = new-object TilesWP.TilesWP

You'll probably find it interesting to see an actual implementation of this.

Note:

If you actually don't want to create a custom implementation of the tiles webpart, but all you are trying to do is display a promoted links view, you can use XsltListViewWebPart

$webpart = New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart
$webpart.ListId = $tilesList.ID
$webpart.ViewGuid = ($tilesList.DefaultView.ID).ToString("B").ToUpper()
$webpart.ChromeType = "None"
$webpartmanager = $web.GetLimitedWebPartManager("/Pages/Home.aspx",[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpartmanager.AddWebPart($webpart, "Header", 1)
$webpartmanager.SaveChanges($webpart)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.