Monday, October 27, 2014

SPListItem Extension Methods To Get And Set Field Values

Followings are the extension methods for SPListItem class.

Single line of text, Multiline lines of text and Choice(Single)



Choice (Multiple)



Number, Currency



DateTime



Lookup (Single)



Lookup (Multiple)



Yes/No



User



User Collection



Hyperlink or Picture



Managed Metadata (Single)



Managed Metadata (Multiple)




You can download SPListItemExtensions.cs file containing all above extension methods.

Monday, October 20, 2014

Relative Path Using SPUrlExpressionBuilder & URL Tokens

Many time you need to provide relative path when you are working with image, js or css files. Of course you can use hard coded (Absolute) path but it fails after changing domain name or environment. Absolute path is more useful when linking to another website. You can also build relative path using ../ but it fails when you add reference in master page.

Fortunately, SharePoint provides SPUrlExpressionBuilder and URL tokens to generate the relative url. You can use following url tokens:
  • ~Site - Resolve to current web
  • ~SiteCollection - Resolve to current site collection root
URL Tokens can be use only with server side control. Followings are snippets to generate the relative url:

JavaScript



CSS



Favicon



Image



Hyperlink



Server side


SharePoint 2013 search users/group autocomplete with presence 2.0

Recently I have updated my SharePoint 2013 search users/group auto complete with presence plugin on CodePlex. Now it will look for search suggestions along with users.

Features

  • Update SharePoint 2013 search input box to search people with the presence
  • Redirect to Profile page on selection [optional]
  • Show user picture with presence [optional]
  • Show search suggestions

Prerequisites

  • SharePoint 2013
  • jQuery 1.8.x +
  • jQuery UI JS 1.10.x
  • jQuery UI CSS 1.10.x

Solution Deployment

  • Deploy Arya.SearchUser.wsp using following PowerShell Command:
    add-spsolution -LiteralPath "SOLUTION_LOCATION\Arya.SearchUser.wsp"
                        
  • Activate "SearchUserFeature" for particular WebApplication from Central Admin

Manual Installation

Settings


mySiteUrl :

My site url. User will redirect to profile page url. default: ""
e.g. http://PROFILEURL/person.aspx?accountname=NETWORID

redirectToProfilePage :

If true then user will be redirected to profile page url on selection. default: false

maxSuggetions :

Maximum suggestions to display. default: 10

showpicture:

Show user picture. default: true

showInitials:

Show Gmail like text avatar in case user profile image in not available. default: false

showSearchSuggetions:

Show search suggestions. default: true

principalType:

Principal type to search. default: 1
options:
  • 0 - User, DL, SecGroup, SPGroup
  • 1 - User
  • 2 - DL
  • 4 - SecGroup
  • 8 - SPGroup

Enable search suggestions:

  • Go to Central Admin
  • Click on "Manage service applications" under "Application Management"
  • Click on Search Service Application
  • Click on "Query Suggestions" under "Queries and Results" in left navigation
  • Check "Show search suggestions" and click "Save Settings"

Search without picture


Search with picture


Contact card


You can download the latest source code from codeplex

Thursday, August 14, 2014

Snippets to create custom SharePoint forms/pages

Many times I create custom SharePoint forms in my solutions. More appropriate way is to create SharePoint form using InputFormSection. InputFormSection takes care of the layout and positioning of your controls. You can add InputFormControl containing asp.net/SharePoint controls under InputFormSection.

Add the following references in .aspx pages:


Container for InputFormSection:


Followings are some snippets of few common controls I use in custom SharePoint forms/pages:

Texbox








Multiline Textbox








Dropdown





Checkbox







Radio button








Url Field











File Upload









People Picker







Button




Tuesday, August 12, 2014

Sharepoint Selector Controls for custom administration pages

Sharepoint comes with four selector controls to choose destination elements for the operations.  These controls can be used in custom administration pages.  You can locate this controls under Microsoft.SharePoint.WebControls namespace.  To add selector controls you have include following page directive:



WebApplicationSelector

WebApplicationSelector control allow user to get or set the web application.




SiteAdministrationSelector

SiteAdministrationSelector control allow user to get or set the site collection.





WebAdministrationSelector

WebAdministartionSelector allow user to gets or sets the Web.  The web selector requires that SiteSelector not be a null reference.  So you have to use SiteAdministartionSelector to use this control.


ListAdministrationSelector

ListAdministrationSelector allow user to get or set the List or Document Library.  The List selector requires WebAdministartionSelector.  So if you want to use list selector then you have to use WebAdministartionSelector as well as SiteAdministrationSelector.





To get the selected values from above controls use CurrentItem property:

Friday, August 1, 2014

Get operating system name from HttpRequest

I was creating a HttpModule in SharePoint to track the request related data such as browser name and client platform. If you are tracking request related data then you must be familiar with System.Web.HttpBrowserCapabilities class. HttpBrowserCapabilities class enables the server to gather information on the capabilities of the browser that is running on the client. I was using HttpCapabilitiesBase.Platform Property to get the client operating system name. But for Windows platform it was returning "WinNt" instead of actual operating system name. After doing some research I noticed that Request.UserAgent returns operating system information along with operating system version number. 

Here is my code to get the Operating System name from Request.UserAgent

If you find more combinations please add it to comments section.

Thursday, July 17, 2014

SharePoint 2013 Lync Presence using jQuery

In my last couple of assignments I was working on Lync presence for user in SharePoint 2013. After that I decided to create a jQuery plugin to render user presence in SharePoint 2013. This plugin  renders lync presence on the basis of account name ("DomainName\\UserName" or "i:0%23.f|membership|username@domain.com"). I have also uploaded the plugin to codeplex

Prerequisites


  • SharePoint 2013
  • JQuery 1.8.x +


Installation




Settings


type:


Output for the lync presence. default : "default"
Options
     default
     withpicturesmall
     withpicture
     pictureonlysmall
     pictureonly
     presenceonly

redirectToProfile:


Redirect to profile page after click. default : true

Output


Default

With Picture [Small]

With Picture

Picture Only [Small]

Picture Only

Presence Only

Contact Card

You can download the latest source code from codeplex
Please report any bugs or feature requests in comments.