Monday, May 30, 2011

Getting the Current User's SharePoint Group Name - SharePoint 2010, InfoPath 2010

Since I did not write a post about SharePoint 2010 for some time, thought to write a pretty interesting post about how to get the logged in user's SharePoint group name using InfoPath functionalities. And for those who don't like to do some coding to get the thing done, they will surely like this approach. Since this is going to to be a longer post, I think it's better to go as a step by step approach, so I will start from Step 01.

Step 01.

Select the Custom List and on Ribbon under List click Customize Form. Then the List will be opening in the Microsoft InfoPath Designer 2010 .

Step 02.

Click on Manage Data Connections in InfoPath Designer. Then add two receiving data connections as following.
  • First we will add a receiving data connection for web service UserProfileService.
Receive Data Connection for UserProfileService
SOAP Web Service
  • In the text box type, http://ServerName/_vti_bin/UserProfileService.asmx.
  • From the list of web methods, select GetUserProfileByName.
Web Method - GetUserProfileByName
  • Click Next and you'll be asked for set the value for Account Name, leave it blank as doing it would get the current User.
AccountName - Leave it blank
  • Tick Automatically retrieve data when the form is opened.
Tick - Automatically retrieve data when the form is opened
  • Click Finish.
  • Then let's start creating the receiving data connection for web service UserGroup.
Receive Data Connection for UserGroup

SOAP Web Service
  • In the text box type, http://ServerName/_vti_bin/UserGroup.asmx.
  • From the list of web methods, select GetGroupCollectionFromUser.
Web Method - GetGroupCollectionFromUser
  • Click Next. You will be asked to set sample value for UserLoginName. In that screen click Set Sample Value and in the appearing box type domain\Administrator.
userLoginName - Domain\Administrator
  • Click OK and Next. In the appearing screen Untick Automatically retrieve data when the form is opened.
Untick - Automatically retrieve data when the form is opened
  • Click Finish. Now you have successfully created two receiving data connections.

Step 03.

Now we will have to modify the xml schema for GetGroupCollectionFromUser data connection. For that we we will need to extract the InfoPath form. To extract the form, in InfoPath form go to File and Publish and then Export. Select a Folder to export the files and the form will be extracted.


Step 04.

Now when the form has finished exporting, go to the folder you have selected. You will see a list of files that has been created in Export process.  But in our case we only focus on GetGroupCollectionFromUser.xsd (the xml schema for GetGroupCollectionFromUser data connection).

Exported Files
  • First Close the InfoPath Designer. Because you can't edit files when are being used by the InfoPath designer.
  • Open GetGroupCollectionFromUser1.xsd in a text editor (I prefer Notepad++) and edit it as below.
    • Find the following line. Normally it's the 2nd line of the file.
                <s:import namespace="">
    • Add following below above line.
<s:complexType name="GetGroupCollectionFromUserType">
      <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="Groups">
            <s:element maxOccurs="unbounded" name="Group" >
                <s:attribute name="ID" type="s:unsignedShort"></s:attribute>
                <s:attribute name="Name" type="s:string"></s:attribute>
                <s:attribute name="Description" type="s:string"></s:attribute>
                <s:attribute name="OwnerID" type="s:unsignedByte"></s:attribute>
                <s:attribute name="OwnerIsUser" type="s:string"></s:attribute>
    • Find the following part.
<s:element name="GetGroupCollectionFromUser">
  <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string">
    • Replace it with the following code.
<s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType">

Step 05.

Now right click on the manifest.xsf and choose Design. Choose GetUserProfileByName data connection and apply rules on the PropertyData field as following.
  • In Fields bar click on Show Advanced view.
Advanced view of Fields
  • Under Fields Select GetUserProfileByName (Secondary).
  • Then Add a rule. 
GetUserProfileByName (Secondary)
  • The rule condition is Name="AccountName", rule type is Action.
Select a field or group
GetUserProfileByName - Name
Type Text
    • Type "AccountName".
Type "AccountName"
  •  The rule actions are:
    • Set field’s value. Under Field, Set Field as follows.
GetGroupCollectionFromUser (Secondary) - Name
    • Then Under Value, Set Value as follows. Click fx and then Insert Field Or Group.
GetUserProfileByName - Value
    • Don't Click OK yet. Click Filter Data. The Click Add.
Select a field or group
GetUserProfileByName - Name
    • Click OK.
Type Text
Type "AccountName"
    • Click OK. Then you will get something like this.
Complete Formula (fx)
    • Click OK.
    • Then add another Action. Action is Query for data from GetGroupCollectionFromUser. 
Query for data - GetGroupCollectionFromUser
    • Click OK.
Step 06.

Now create a formatting rule for a field that you want to disable/hide if current user is not member of a given SharePoint Group. Put a condition as below, where the "LCGD Clerk" is the SharePoint Group Name.

Select a field or group
  • Set the Name in GetGroupCollectionFromUser (Secondary Data source).
GetUserProfileByName - Any occurrence of Name
Type "LCGD Clerk" (SharePoint Group Name)

Step 07.

Now Everything is completed. Final step is Publish the form.

Hope you all got a good idea about how to get the Current User's SharePoint Group Name using InfoPath functionalities. Appreciate your feedback.

Happy Coding.


Thursday, May 19, 2011

Started using jQuery

jQuery - This thing has been going around and around through my head for some time and thought why not put my hands on it and check what this jQuery really is and do some things using jQuery. Started learning from the scratch few minutes ago and so far so good.

Before started putting my hands on developing, read some articles to get some basic knowledge on what jQuery really is and what are the things that can be done using jQuery. It seems like for web developers and web designers, there is a lot you can do and you will never even imagine how a simple and small code snippet can do such things and thats of course by calling nicely designed functions in jQuery JavaScript library.

jQuery is a cross-browser JavaScript library which will simplify JavaScript programming. All you need is downloading jquery.js file and a simple text editor (well I am using notepad++).

You can download jquery.js from here.

Happy Coding.


Wednesday, May 18, 2011

Basics of ASP.NET MVC

If you are developing web applications using ASP.NET, I am sure every one must have gone through this thing called ASP.NET MVC. So for a beginner or even for myself to keep some things remembered about ASP.NET MVC, thought to write this post.

The ASP.NET MVC Framework is a web application framework which is used to develop web applications in Model-View-Controller design pattern (I will briefly describe about the MVC pattern latter in this post). Actully ASP.NET MVC Framework is a part of the ASP.NET Web application framework which comes under Microsoft .NET framework.

There are exactly two different programming models which can be used to create ASP.NET Web Applications. One is ASP.NET MVC and the other is ASP.NET Web Forms. Since in here we are mainly focusing on ASP.NET MVC, we'll move forward with that.

First of all to get a whole imaginary idea of MVC, take a good look at the following image.

In ASP.NET MVC everything is handled by the above 3 main components which are Model, View and Controller. Let's start with the Model component.

  1. Model Component
    • Model represent the data or activity corresponding to the application. Simply means it represents the state of the application. (Ex: DB)
  2. View Component
    • A View is responsible for rendering a user interface to display information which it accepts from Controller Component. (Ex: Web Pages)
  3. Controller Component
    • A controller handles interactions and then updates the model to reflect a change in state of the application, and then passes information to the View. (Ex: Web Services)
When creating ASP.NET MVC Web Applications, the namespace that contains classes and interfaces that supports the ASP.NET MVC is System.Web.Mvc.

Hope you get something out of this post. Appreciate your feedback.

Happy Coding.


Tuesday, May 10, 2011

Silverlight 4 Image Slideshow

Since Silvelight is giving more rather than similar functionalaties when comparing to Adobe Flash, thought to write a post about some simple browser plugin which I have developed using Microsoft Silverlight 4.

First of all Microsoft Silverlight is an application framework somewhat similar to actually based on Microsoft .Net framework for developing browser plugins and rich internet applications.

For More information about Microsoft Silverlight visit,

This plugin is developed using Visual Studio 2010 and Microsoft Silverlight 4.


Please feel free to give me your feedback. And if anyone needs the fully functioning source code please do contact me or leave a comment here.

Happy Coding.