Friday, 15 November 2013

Add Custom Web Parts to a page and Connect them using PowerShell

These days I am working heavily on SharePoint CSOM and BCS (Business Connectivity Services). I have created a sandbox package with multiple custom business data and html form data web parts.

The reason why I am writing this blog is to share with you some of the cool stuffs I did with PowerShell in the project.

I have written many automation scripts to create web part page, add web parts to this page and then connect to them on a single click using PowerShell.

First thing first…

1.       Create a web part page using PowerShell:

2.       Add web part to this page:

3.       Connect web parts in a page: In this script I have shown how we can connect

a.       Query String filter Web Part with Business Data List Web Part

b.      Query String filter Web Part with Business Data Item Web Part

c.       Business data List Web Part with Business Data Item Builder Web Part


Have Fun!

Isha Jain

Thursday, 25 April 2013

Paste content into SharePoint with no formatting

Hello Again,

These days I am working heavily into SharePoint Ribbon customization. If you have not read my previous blog on this, I would recommend you to read Previous Ribbon Blog before reading this one.

SharePoint 2010 brings the new evolution in user interface and have brought common functionalities into same page by introducing the Ribbon concept.

In SharePoint user is allowed to copy content from various sources like email, office applications like word, excel  and paste into SharePoint.

By default there are two ways to paste content into SharePoint from ribbon.

1. Paste (paste content with styles and formatting)
2. Paste palintext (paste content without styles but keeps the formatting)

However; pasting the content even as Plain text from word and other sources into SharePoint  introduces breaks and other markup issues in Html.

Paste  (format:break line and color:Blue)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

Paste Plaintext (only format:break line)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null
Write-Host "Hello All"

I wanted to achive something shown below.

Paste with no formatting (no format no color)
Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | out-null Write-Host "Hello All"

I have created a sandbox solution and added element.xml as shown below. On click of this flyout anchor menu I have called a javascript function as defined in commandaction attribute in the command handler.

Hope you find this useful.
Isha Jain

Friday, 5 April 2013

How to find a SharePoint field from GUID


I have been in a scenario where I need to find one of the SPFields from its GUID. Its again PowerShell who saves my time.

$site = Get-SPSite -Identity "http://Site"

That's it, I am done!!!

Isha Jain

Monday, 25 March 2013

Find all the sites where the feature is activated


I have been struggling how to find out the lists of sites where my feature is deployed.

Below PowerShell command which helped me.

Instead of  using "Write-Host", I have used "Write-Output" which will give output in my output.txt file.

Note: Write-Host will write the output in the console while Write-Output helps to write the output in some file.

Hope this is useful.

Monday, 11 March 2013

Fetch Rss feeds into SharePoint List

I  had been into a scenario where I need to search the results from one of the Rss feeds into SharePoint search results page.

This means the data from this Rss feeds had to be into SharePoint content database and then SharePoint search crawler will crawl the content and made the content search able into the results page.

So I came up with a design of fetching the data from the Rss feeds into the SharePoint list in an hourly basis and will display the top 10 results into the home page and user can search on this Rss feeds.

In this design I need
1. Rss Feed link (
2. SharePoint Custom list which will store the content from Rss feed.
3.Content Editor web part (CEWP) to display the top 10 results in to the home page.
4.Fetch the latest results into the SharePoint list in every one hour.

I am using SPServices to add/update the Rss Feeds into SharePoint list. In order to know more on SPServices and how to perform CRUD operations, Please visit my blog on CRUD operations using SPServices.

Step1: Fetch the Rss Feeds

At First, Created  a Custom List called RSS Feed with the custom columns Content, PublishedDate, FeedLink and Title.

So what I am doing here is, Calling Google feed api using  jQuery ajax to fetch the Rss feed by passing query parameters, q as Rss Feed url link and num to -1 to fetch all the results back into json object and then iterating each object and storing into SharePoint list.

Step2:Store the feeds into SharePoint List

Step3: Display the content from SharePoint List in the home page using CEWP.

Step4: Fetch the latest feed in every hour.

Hope you find this blog useful.

Isha Jain

Sunday, 10 March 2013

SharePoint Ribbon Customization

Ribbon is one of the new features introduced in SharePoint 2010. After office client, Microsoft introduced ribbon in the similar fashion in SharePoint.

Ribbon in SharePoint 2010 provides the common place for most of the controls that you will need, Ribbon  is divided into basic four sections as shown in Fig 1 below.

1. Tab
2. Group
3. Controls
4. Contexual Tab

The architecture of Ribbon allows you to customize by creating xml files.

Inorder to understand how SharePoint implements its Ribbon, there is a XML element file at
%Program Files %\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.XML

If you open this xml file, you will see that its a huge file. Don't get afraid with this huge file.
Lets understand how SharePoint implements the Ribbon functionality.

The main element in the "CMDUI.xml" file is the "CommandUI" element, this element holds all the controls and the templates for the Ribbon.

Ribbon element holds all the controls like Tabs, Group, Controls, Contextual Tab.

Templates element has GroupTemplate element. Each GroupTemplate element specifies the mode in which the controls within that group will be rendered.

As you can see in the ribbon image Fig 1, some of the controls are rendered as large icons whereas  others like "Page History", "Delete Page" etc. (under Manage group) are rendered in medium size icons. All of these are controlled by GroupTemplate element.

Now, Lets have a close look at Ribbon element. Ribbon element has two child elements "Tabs" and "ContexualTabs". Each of these element further has Groups and Controls element which hold the html contols like label, textbox , combobox, dropdown. etc.

I hope you have got the clear understanding of the CMDUI.xml file.

Now lets try to customize the ribbon. In this example I am going to add the caption to the table when a user inserts the table into the page. 

When a user edits the page and inserts the table into the page, "Table Tools" contextual tab shown below is displayed. What I am trying to achieve using this custom control is, when user enters some text into this highlighted textbox and hits save,  I am adding the Caption child element to the table. This is achieved by specifying the custom .js code into the command handler element.

Adding any custom controls into the ribbon can be achieved by creating custom action element.xml file in SharePoint 2010.

The CustomAction element has two main elements: CommandUIDefinitions and CommandUIHandlers.

CommandUIDefinitions hold all the custom controls definitions and the CommansUIHandlers hold the actions against each controls.

There are few things to keep in mind.
CustomAction Location="CommandUI.Ribbon" -  tells SharePoint that you are adding controls into the Ribbon.

CommandUIDefination Location="Ribbon.Table.Layout.Summary.Controls._children" - tells SharePoint that the controls need to be added into the "Ribbon.Table" contextual tab under "Layout" tab under "Properties" group.

Command attribute of the control is the place you specify what action you need when a user clicks on the control. Action is specified in the CommandUIHandler element. In my example I am adding the caption element to the table.

QueryCommand attribute of the control is fired when the page is rendered. Action is specified in the CommandUIHandler element. In my example I am fetching the caption element of the table and storing into the textbox.

There are few .js files for Ribbon which are present at 14 Hive layouts folder. These files hold the actions (CommandUIHandler) part of the ribbon.

For Rich Text Editor : "SP.UI.RTE.js"
For Publishing Site Rich Text Editor:  "SP.UI.RTE.Publishing.js"

Hope you find this blog useful.

Isha Jain

Saturday, 23 February 2013

CRUD operations using SPServices


These days I am working on client side scripting in SharePoint 2010. I have heavily used SPServices.

SPServices is a JQuery library which interacts with SharePoint web services. It is a script based technology which allows us to talk to SharePoint through its web services.

The syntax is pretty simple, similar like JQuery and other scripting libraries. I have shown below the sample examples to achieve the CRUD operations using SPServices.

Get All the items from the list based on the condition using GetListItems

function ProcessData(xData)
  var ulTag=$('<ul style="list-style:square;"></ul>');  
    var liTag=$("<li></li>").append($(this).attr("ows_Title"))

    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Expires' /></IsNotNull></Where></Query>",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Expires' /><FieldRef Name='Body' /></ViewFields>",
    completefunc: ProcessData

Delete All the items from the list using SPUpdateMultipleListItems

function DeleteAllItemsFromList()
    listName: "Announcements",
    CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",
    batchCmd: "Delete"});

Add item to a list using UpdateListItems

function AddItemsToList(title,content)
   operation: 'UpdateListItems',
   listName: "Announcements",
   updates: '<Batch OnError="Continue">' + 
             '<Method ID="1" Cmd="New">' +
             '<Field Name="Title">'+ title +'</Field>' +
             '<Field Name="Body">'+ content +'</Field>' +
    '</Method>' +
   completefunc: function(xData, Status)

Update item in a list using UpdateListitems

$function UpdateListItem(itemID)
    operation: 'UpdateListItems',
    async: false,
    listName: "Announcements", 
    updates: '<Batch OnError="Continue">' + 
             '<Method ID="1" Cmd="Update">' +
      '<Field Name="ID">' + itemID + '</Field>' + //Specifying the item id is very important here
             '<Field Name="Body">'+content+'</Field>' +
      '</Method>' +
    completefunc: function(xData, Status)


Isha Jain

Friday, 4 January 2013

PowerShell Basic - Speical Character

Its very difficult to remember every syntax and what it refers to when you are working with myriad of languages.

Below are the useful basic Characters which you need when you work in Power Shell.

1. Single Line comment representation : #

Ex. # This is a single line comment 

2. Multiple Line comments representation: <# #>

Ex. <# This is a Multiple

           Line Comments #>


3.Declare a variable: $

Ex. $a=$null


4.Item inside for each loop or current pipeline object : $_

Ex. .... | Foreach {Write-Host $_}


5.Continue command on next line: `

Ex. Write-Host `

      "Hello World!!"


6.Where-Object shortcut : ?

Ex. .... |  1..5 | ? {Write-Host $_ % 2} # Here % represent mod


7.Not Shortcut : !

Ex.  $a=$null | if($a) {Write-Host "$a is not null"}


8.For each Shortcut: %

Ex. .... | % {Write-Host $_}


9. To catch the output of the command and pass it to the another command: |

Ex.  get-process | select-object -first 3

10. Declare Array: @()

Ex. $a= @("one" , "two" , "three")

11. Declare Hash table: @{}

Ex. $a= @{"1" = "one" ; "2" ="two" ; "3" ="three"} 

12. To specify a range: ..

Ex. 1..5 | 

Hope this help