Archive for May, 2011

SharePoint 2010: Ribbon Customization – Adding button in Editing Tool Tab

Scenario:

When a user click in Content Editor web part, a button appear in the “Editing Tool -> Insert” tab.

Resolution:

Following XML did the trick and we deploy it as feature.

<CustomAction
Id=Ribbon.Add.Button

Location=CommandUI.Ribbon>

    <CommandUIExtension>

      <CommandUIDefinitions>

        <CommandUIDefinition
Location=Ribbon.WikiPageTab.PubPageActions.Controls._children>

          <Button

          Id=Ribbon.WikiPageTab.PubPageActions.AddLinkButton

          Sequence=22

          Image16by16=/_layouts/images/PPEOPLE.GIF

          Image32by32=/_layouts/images/PPEOPLE.GIF         

          Command=AddLinkButton

          LabelText=Add Link Button

          ToolTipTitle=Add Link Button

          ToolTipDescription=Create link.

          TemplateAlias=o2 />

        </CommandUIDefinition>

        <CommandUIDefinition

        Location=Ribbon.WikiPageTab.Scaling._children>

          <MaxSize

            Id=Ribbon.WikiPageTab.Scaling.PubPageActions.MaxSize

           Sequence=15

            GroupId=Ribbon.WikiPageTab.PubPageActions

            Size=LargeLarge />

        </CommandUIDefinition>

      </CommandUIDefinitions>

      <CommandUIHandlers>

        <CommandUIHandler
Command=AddLinkButton
CommandAction=javascript:AddLinkButton();
EnabledScript=javascript:returningtrue(); />

      </CommandUIHandlers>

    </CommandUIExtension>

  </CustomAction>

Leave a Comment

PowerShell Script: Change Site Theme

Scenario:

We have customized a site theme as explained in previous post. Now, we need to apply it on Site and all its webs.

Resolution:

$name = [Name of theme]

$filepath = [Path of the theme]

$bytes = [System.IO.File]::ReadAllBytes($filepath + “\” $name);

$site = Get-SPSite(“url of site collection”)

$rootWeb $site.RootWeb

$list $rootWeb.Lists[“Theme Gallery”]

$list.RootFolder.Files.Add($name,$bytes)

$theme = [Microsoft.SharePoint.Utilities.ThmxTheme]::Open

($site,“_catalogs/theme/”$name)


foreach($web in $site.AllWebs)

{

$theme.ApplyTo($web,$false)

}

Leave a Comment

SharePoint 2010: Customize Site Theme

Scenario:

We need to make changes in SharePoint site theme and apply it on site collection and all webs under that site.

Resolution:

We will take two simple changes like changing the color of “Text/Background – Dark 2” and “Text/Background – Light 2” of theme “Convention”.

Enclosed in red rectangle in the figure below are the two colors which needs to be change.


First step is to download the theme “Convention”. Go to “Site Settings” -> “Galleries” -> “Themes”. Save theme on your local disk.

Open it in “PowerPoint 2010” and go to “Design” tab and click on “Colors”, following window will appear:


Click on “Create New Theme Colors..” and following screen will appear:


Change the color of “Text/Background – Dark 2” and “Text/Background – Light 2” as per need and save the theme with different name.

Upload the theme in “Themes” gallery and apply it on the site. Bad news is that it will not be applied on all the webs under the site.

For this, we wrote a PowerShell script available at this url

Leave a Comment

SharePoint: Get All Possible Values of Choice Column Dynamically

Scenario:

We need to populate an asp DropDownList control with all possible values of a choice column created in a specific SharePoint list.

Resolution:

SPList spList = spWeb.Lists[“ListName”];

SPField spField = spList.Fields[“ColumnName”];

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.LoadXml(spField.SchemaXml);

XmlNodeList nodeList = xmlDoc.SelectNodes(“/Field/CHOICES/CHOICE”);

foreach (XmlNode node in nodeList)

{

    ddl.Items.Add(node.InnerText);

}

Leave a Comment

SharePoint 2010: PowerShell Script to Create SiteCollection using Custom Template

Scenario:

We need to write PowerShell script to create site collection using custom template.

Resolution:

First, we need to save site as template. For this, “Site Settings” -> “Save site as template”. Enter site template name, say, testCustomtemplate. After saving, go to “Solution Gallery” and download the testCustomtemplate.wsp.

Second, add the wsp. For this, run SharePoint PowerShell and run following commands:

Add-SPSolution [Path to testCustomtemplate.wsp]

Install-SPSolution –identity testCustomtemplate.wsp

Third, run following script making appropriate changes:

$newSite = New-SPSite -Name [SiteCollectionName] -Url [URL] -OwnerEmail [OwnerMail] -OwnerAlias [OwnerLogin] -SecondaryOwnerAlias [SecondaryOwnerLogin]

Enable-SPFeature -Identity [FeatureGuid] -Url $newSite.Url

$rootWeb = $newSite.RootWeb

$rootWeb.ApplyWebTemplate(“[CustomTemplate]”)

You need to find values of two variables. One is “FeatureGuid” and other is “CustomTemplate”.

FeatureGuid can be found out by simply going to 14 hives, go for folder containing the name “WebTemplate” along with your solution name and copy feature ID. Like we have feature ID {e27e2916-5eb2-4a23-901b-fb3f386136bb}.

CustomTemplate can be manually created by concatenating the name of the solution and feature as under:

{e27e2916-5eb2-4a23-901b-fb3f386136bb}# testCustomtemplate

Or run following simple script after activating the feature on site collection:

$site = Get-SPSite [SiteCollectionURL]

$web = $site.RootWeb

$templates = $web.GetAvailableWebTemplates(1033) //1033 is Culture ID.

Foreach($temaplte in $templates)

{

$template.Name

}

Comments (2)