Archive for July, 2011

SharePoint 2010: PowerShell Script to add / display list as webpart

Scenario:

We were required to add / display discussion forum / discussion board as a webpart on a publishing page.

Resolution:

We used “XsltListViewWebPart” webpart to accomplish above requirement

$webpart New-Object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart

$webpart.ListId $list.ID;

$webpart.ViewGuid $list.DefaultView.ID.ToString();

$webpart.AllowClose $false;

$webpart.AllowConnect $false;

$webpart.AllowEdit $false;

$webpart.AllowHide $false;

$webpart.AllowMinimize $false;

$webpart.AllowZoneChange $false;

$webpart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::None;

$webpartmanager=$web.GetLimitedWebPartManager($pageUrl,

[System.Web.UI.WebControls.WebParts.PersonalizationScope]

::Shared)

$webpartmanager.AddWebPart($webpart, “Zone 1”, 0);

You need to set following variables:

$list = Get the reference of list. In our case, it was discussion forum

$pageUrl = Url of the page

Leave a Comment

SharePoint 2010: PowerShell Script to create Discussion Board / Discussion Forum

Scenario:

We need to create discussion board / discussion forum using power shell script

Resolution:

$spWeb Get-SPWeb $webURL

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DiscussionBoard

$spWeb.Lists.Add(“Discussion Forum”, “Custom List”, [int]$listTemplate)

Thanks to my friend Abdur Raheem 

Comments (1)

SharePoint 2010 Ribbon: Hide Button from Discussion Forum New Item Window

Scenario:

We need to hide “Save / Cancel / Paste / Cut / Copy / Attach File” buttons from discussion forum “New Item” window:

Resolution:

Following XML worked:

<CustomAction


Id=RemoveRibbonButton


Location=CommandUI.Ribbon
RegistrationId=108


RegistrationType=List>

<CommandUIExtension>

<CommandUIDefinitions>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Commit/>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Clipboard/>

<CommandUIDefinition
Location=Ribbon.ListForm.Edit.Actions/>

</CommandUIDefinitions>

</CommandUIExtension>

</CustomAction>

</Elements>

 

Before:

After:

Comments (4)

SharePoint 2010 event @ Hajvery University

I spoke at a session organized by Microsoft Pakistan and Hajvery University of Pakistan. The event held on Monday, June 27th, 2011. I presented on SharePoint 2010 for students with CS and management background. The snaps of the event are available @ https://picasaweb.google.com/farhan.faiz/SharePoint2010EventHU.

Thanks to Mubhashir Saleemi, people at HU and people at Microsoft Pakistan for the session.

Comments (1)

SharePoint: Incompatible Web Part markup detected. Use *.dwp Web Part XML instead of *.webpart Web Part XML

Scenario:

We deployed a webpart and when tried it to add it on the page, following error occurred:

Incompatible Web Part markup detected. Use *.dwp Web Part XML instead of *.webpart Web Part XML.

Resolution:

This error occurs when you have not inherited your class from “System.Web.UI.WebControls.WebParts.WebPart”. We have inheritated our class from “Microsoft.Office.Server.WebAnalytics.Reporting.WhatsPopularWebPart” class as we were customizing OOTB “WhatsPopularWebPart”. The resolution is to create your own “.dwp” file. Copy pate following XML, make appropriate changes and save it with “.dwp” extension.

<?xml version=”1.0″?>

<WebPart xmlns=”http://schemas.microsoft.com/WebPart/v2″&gt;

<Assembly>[AssemblyName],Version=[X.X.X.X], Culture=[XXXXX],PublicKeyToken=[XXXXXXXX]</Assembly>

<TypeName>WebPartNamespace.WebPartClassName</TypeName>

<Title>WebPartTitle</Title>

<Description>WebPartDescription</Description>

</WebPart>

One quick way is to open “.webpart” file and replace values.

Second step is to go to 14 hives or 12 hives [C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES], found the feature folder. Delete “.webpart” file and paste “.dwp” file. Repeat the same process in the SharePoint installation. Go to Site Collection Settings-> Web parts (under Galleries). Delete “.webpart” file and upload “.dwp” file.

Source:

http://blog.sharepointdevelopment.nl/post/Unable-to-add-selected-Web-Part-Incompatible-Web-Part-markup-detected.aspx

Comments (2)