Wednesday, 14 April 2010

Convert PersonOrGroup field to SPUser

There is no straight way to convert "personorgroup" field to SPUser object. Here the way to convert it using SPFieldUser object.



private
SPUser GetUser(SPListItem item, SPField userField)
{
string currentValue = item[userField.Title].ToString();
SPFieldUser field = (SPFieldUser)userField;
SPFieldUserValue fieldValue = (SPFieldUserValue)field.GetFieldValue(currentValue);
return fieldValue.User;
}

Tuesday, 13 April 2010

Create Open Tool Pane link in custom sharepoint webpart.

Below is the way to open a tool pane from custom webpart.


<a href=\"javascript:MSOTlPn_ShowToolPane2Wrapper('Edit', this,'" + this.ID + "')\">Open tool pane</a>


Just add this link in the webpart and it will do the trick. It even works fine in SharePoint 2010!!!




Happy Coding...



Use [Me] in CAML query when user is part of group

[Me] keyword does not work when user is part of a sharepoint group and that group is assigned to any item or list. Here is the way to make it work
<Where>
                <Or>
                                <Membership Type="CurrentUserGroups">
                                                <FieldRef Name="AssignedTo"/>
                                </Membership>
                <Eq>
                                <FieldRef Name='AssignedTo'/>
                                <Value Type='Integer'>
                                                <UserID Type='Integer'/>
                                </Value>
                </Eq>
                </Or>
</Where>