Hello,
Today new problem and solution.
Problem
In our project, we have to delete the webpart using powershell script. I am passing the webpart type name as a parameter and retrieving through all webparts and comparing the webpart type name with the passed type name. But it seems that this condition never worked. After digging into more details it found that powershell always showing the our webpart type name as ErrorWebPart(Microsoft.SharePoint.WebPartPages.ErrorWebPart). Also this webpart appears correctly on the page and also it shows the correct type on the page when I check by URL?Contents=1.
Solution
Our webpart is ContentQuery webpart and we have deleted the Item Style for this webpart (Since we have to delete the Content Query webpart itself) from the ItemStyle.xsl and that’s why it was shown as ErrorWebPart. The Error webpart is placeholder for the webparts which have some problems.
The solution to this problem is to use RepresentedWebPartType property of ErrorWebpart. It shows the correct type. The webpart which works correctly for them value of RepresentedWebPartType is Null.
So my condition became:
- $WebPartCollection = $webpartmanager.WebParts
- for($i=0;$i -lt $WebPartCollection.Count; $i++){
-
- if($webpartmanager.Webparts[$i].RepresentedWebPartType.Name -eq $webPartName){
- #delete webpart code
- }
- }
Where
- $webpartmanager = Webpart Manager obtained from the current page
- $webPartName = Webpart which I want to delete
Thanks!
Enjoy reading.