Custom Properties in SharePoint 2010 Webparts

This post aims to provide a glimpse into how Custom Properties can be utilised on SharePoint 2010 Custom Webparts. Indubitably Custom Properties are great way to facilitate extra functionality and build dynamic custom webparts that respond uniquely based on the value assigned to the custom properties.

Pre-requisite: I have used Visual Studio 2010, Visual Web Part Template to demonstrate a simple example.

Begin by creating a simple property in the WebPart.VB/CS file (just above the CreateChildControls() method call).

' Declare Custom Property

Dim _Flag As Boolean = Nothing

<Category("Configuration"), Description("Configure the custom property"), WebBrowsable(True), Personalizable(True), WebDisplayName("Set Flag Value")> _

Public Property CustomProperty() As Boolean


Return _Flag

End Get

Set(ByVal value As Boolean)

_Flag = value

End Set

End Property

Now change the code in CreateChildControls() method

Protected Overrides Sub CreateChildControls()

'Dim control As Control = Page.LoadControl(_ascxPath)


Dim control As MyWebPartUserControl = DirectCast(Page.LoadControl(_ascxPath), MyWebPartUserControl)

control.CustomProperty = CustomProperty


End Sub

Finally, in the WebPart.ascx.VB/CS, add the same property

Public Property CustomProperty() As Boolean


Return _Flag

End Get

Set(ByVal value As Boolean)

_Flag = value

End Set

End Property

That’s it. Deploy the webpart and whilst you edit setting of the webpart you can set the property value as and when required. Furthermore, you can add logic for webpart to behave differently based on the value of the property set. What’s interesting is that Webpart Manager uses in built personalisation so while the Webpart has True for a user it can have False for other user. Brilliant.

Integrating Project Server 2010 with SharePoint 2010

There is always a feeling of excitement, anticipation and trepidation when it comes to integrating technologies. In this article I am attempting to write comprehensively on integrating Microsoft Project Server 2010 and the almighty SharePoint 2010. Come to think of this partnership, it is inevitable, since as at the heart of SharePoint is collaboration and people working together.

This article delves into configuration of Project Server 2010 and what to expect.

1. Preliminary Install

Install Microsoft Project Server 2010 SP1 on the same server where SharePoint 2010 is running. I will not cover the steps to run the DVD installer and walking through the install process.

2. Let’s get Configuring

I assume now MS Project Server 2010 SP1 is now installed and set up. Inform you users there might be slow performance of SharePoint (approx. 1-4 min)

 3. Preliminary Check

Central Administration ~ Manage Service Applications

* ensure you already don’t have Project Server Related running

 4. Launch Configuration Wizard

Central Administration ~ Configuration Wizard

If Configuration Wizard is missing; either the account context in which you are attempting to configure Project Server does not have enough permission to launch Central Administration Configuration Wizard / ideally your account should be Farm Administrator or equal.

* If you have the right level of permission try closing the Central Administration on Server and open Central Administration as Administrator (Right click > Run as Administrator)

 5. Run Wizard

Start the Configuration Wizard ~ Yes walk me through the configuration of my farm using this wizard

Ensure you check/select Project Server Service Application ~ Hit Next ~ ‘Processing’

* This might cause your SharePoint to slow down during the installation

Once it has finished It will take you to ‘Configure your sharepoint farm’ section. Unless you want to create a new site etc. SKIP on this section. You should now get the message : This completes the Farm Configuration Wizard

Site Title: N/A
Site URL: N/A

Make sure in list of service appliations you have :
Project Server PSI Service Application


 6. Check Setup

Central Administration ~ Application Management ~ Manage Service Applications

You should now see > Project Server Service Application – Project Server PSI Service Application should now be in Started mode.

 7. Let’s Get Provisioning

Click on the above ~ Create Project Web App Site

  1. Should auto-populate, change anything that is required to be changed
  2. You can remove PWA and give it a more meaningful name
  3. Once you have checked and submitted request
  4. Status 1: Waiting for resources
  5. Status 2: Creating project web app site
  6. Status 3: Provisioning databases (normally takes time)
  7. Status 4: Configuring the new project web app site
  8. Status 5: Provisioned

 That’s it browse to your new PWA site. I hope this has been helpful

 How to manage User Settings/Permissions on PWA

To be honest this could be written as a dedicated blog post but thanks to authors of some key resources below.


ListViewByQuery Webpart in SharePoint 2010

This is a quick post on writing a custom ListViewByQuery WebPart on a designated SharePoint 2010 site. By using a ListViewByQuery Control, developers can easily create a default looking ListView Webpart with added bespoke functionality as they have the luxury of rendering desired caml query to pull data out from an existing list. Perhaps the biggest advantage is that you can present ListViewByQuery WebPart on a different site especially when you want to work within the confines of your SharePoint permission security layer.

I have deployed the ListViewByQuery WebPart inside a custom webpart. I would recommend you to use Visual Studio 2010Empty SharePoint Project (then) – Add New Item – Web Part (Template) for this solution. This will give you all the mapped folders and files etc so nothing for you to worry about. Open your UserControl.ascx File and add the following.

<SharePoint:ListViewByQuery runat="server" id="LVWP" />

Now open the UserControl.ascx.vb file and add the following.

LVWP.List = SPContext.Current.Web.Lists("Some List")
Dim caml As SPQuery = New SPQuery(LVWP.List.DefaultView)
caml.Query = "<caml>Desired CAML Syntax</caml>"
LVWP.Query = caml

This is it, now your ListViewByQuery WebPart is ready to be used on the page. For full access to its properties and methods follow the link.

Noteworthy Anomalies

I have found ListViewByQuery WebPart known for not having:

a)    SharePoint 2010 Ribbon being activated when you click on the List Item.

b)    No Access to DataSheet View.

c)    No ‘Add New Item’ option either.

Needless to say, it is a good reporting tool. Please continue on Google Trails or MSDN SharePoint 2010 Development & Programming Forum if you want to further investigate the above.

SharePoint Group Permissions on SharePoint Site

In this post, I would like to discuss how to report on or retrieve SharePoint User Groups, SharePoint Users and Domain Groups on a given site or a site collection. Although this information is available to SharePoint Administrators by clicking on ‘Site Actions’ and ‘Site Permissions’, there are occasions when programmatically this information might be required.

Using site As New SPSite("http")
For Each _site As SPWeb In site.AllWebs
Using Web As SPWeb = _site

For Each ra As SPRoleAssignment In Web.RoleAssignments
' Site Groups
If TypeOf ra.Member Is SPGroup Then
‘ Business logic

' Site Group Permissions
For Each rd As SPRoleDefinition In ra.RoleDefinitionBindings
‘ Business Logic
End If

' Site Users / Domain Groups
If TypeOf ra.Member Is SPUser Then
‘ Business Logic

' Site Users / Domain Groups Permissions
For Each rd As SPRoleDefinition In ra.RoleDefinitionBindings
‘ Business Logic
End If


End Using

End Using

In the code above I am traversing through a site.allwebs to get the SharePoint Groups, Sharepoint Users and Domain Groups on the site. You can make this further interesting by finding out if site has unique permissions or not or if any list on site has unique permissions.

Also using the same code for a SPWeb instead of site.allWebs in a loop you can query the permissions to different groups on a single SharePoint site.

Autocomplete on Sharepoint DropDownList Column

I am merely writing this for my personal reference.

In an effort to incorporate a SharePoint Lookup Column appearing as a DropDownList it became imperative to think about presenting large amounts of selections to end users and how they would interact with it.

In terms of usability, it just was not an option.

Although, there are a host of options available for creating a AutoComplete behavior this includes; CustomFields, Third Party Features, etc. However, I wanted a simple yet effective solution without breaking alot of sweat.

To begin with head over to the following sources and download these files:

jquery-1.8.3.min.js @
jquery.SPServices-0.7.2.js @
jquery.SPServices-0.7.2.min.js @

Once you have downloaded the above, Create a Document Library in desired SharePoint Site where you would like to implement AutoComplete behaviour. Now, add The jquery files to the Document Library created.

Now just above your ListView (allitems.aspx or whateverview.aspx) Add a new Content Editor WebPart on the page using Site Actions > Edit Page option. From the Ribbon locate Markup and pointing inside the CEWP select HTML > Edit HTML Source. Now add the following –

<script type="text/javascript" src="../DOCUMENTLIBRARYNAME/jquery.SP.Services-0.7.2.js"></script>
<script type="text/javascript" src="../DOCUMENTLIBRARYNAME/jquery-1.8.3.min.js"></script>

<script type="text/javascript">
sourceList: "NAME OF LIST",
numChars: 3,
ignoreCase: true,
slideDownSpeed: 200,
debug: false

Now, hopefully you should your DropDownList with (NONE) editable and pulling back the LookUp Column you attached your Column to. For adding SharePoint GetListItems() follow the link below.


Anita (2010)
Marc D. Anderson (2011)

Process Batch Data in SharePoint

In this post, I would like to illustrate how to use XML based Process Batch Data to a SharePoint list. Using the XML based batch data, it is relatively easier to update a large volume of data/items on a SharePoint list. Here, I am launching a CAML query on SharePoint list (where ‘Status’ column contains ‘woohoo’) to return a SPListItemCollection. Once the relevant list items are returned, then using the web.ProcessBatchData, I update the SharePoint list (‘Status’ column with ‘woohoo’ to ‘yahoo’).

Private Sub ProcessBatchData()

Dim siteCollectionUri As Uri = New Uri("urlofsitewithdesiredlist")
Using oSite As SPSite = New SPSite(siteCollectionUri.ToString)
Using oWeb As SPWeb = oSite.OpenWeb
Dim _list As SPList = oWeb.Lists("ListName")
Dim _items As SPListItemCollection = GetItems(_list, "Woohoo")
If _items IsNot Nothing Then
RunBatchDataProcess(oWeb, _items)
End If
End Using
End Using
End Sub

Private Function GetItems(ByVal _List As SPList, ByVal CAMLQueryTerm As String) As SPListItemCollection
Dim _Qry As SPQuery = New SPQuery
_Qry.Query = "<Where>" & _
"<Eq>" & _
"<FieldRef Name='Status' />" & _
"<Value Type='Choice'>" & CAMLQuery Term & "</Value>" & _
"</Eq>" & _

Dim Results As SPListItemCollection = _List.GetItems(_Qry)
If Results.Count.Equals(0) Then
Return Nothing
Return Results
End If
End Function

Private Sub RunBatchDataProcess(ByVal oWeb As SPWeb, ByVal _Items As SPListItemCollection)
If Not _Items.Count.Equals(0) Then
Dim BatchCmd As String = String.Empty
Dim BatchString As StringBuilder = New StringBuilder
Dim guid As String = _Items.List.ID.ToString

Dim BatchFormat As String = "<?xml version=""1.0"" encoding=""UTF-8""?>" + _
"<ows:Batch OnError=""Return"">{0}</ows:Batch>"

Dim MethodFormat As String = "<Method ID=""{0}""><SetList>{1}</SetList>" + _
"<SetVar Name=""Cmd"">Save</SetVar>" + _
"<SetVar Name=""ID"">{2}</SetVar>" + _
"<SetVar Name=""urn:schemas-microsoft-com:office:office#Status"">{3}</SetVar>" + _

'Construct Caml for the XML above
For i As Integer = 0 To _Items.Count - 1
Dim id As Integer = _Items(i).ID
BatchString.AppendFormat(MethodFormat, id, guid, id, "Yahoo")

BatchCmd = String.Format(BatchFormat, BatchString.ToString)

' Process batch updates
Catch ex As Exception
Throw ex
End Try
Exit Sub
End If
End Sub

Other instances where one could utilise ProcessBatchData are if an existing SharePoint list needs to be copied to a new list to new columns and I am sure there are many occassions this would come handy.