June 08, 2014

PowerShell Create lookup, how to create cross site lookup in SharePoint

SharePoint  gives us an easy way to create lookup columns in same site (in developers language same Web ;) ) but some time we have to create lookup column between two different sites, well there is no direct option provided by Microsoft. But there is simple way to do it using PowerShell.

All you need to know is web/Site names and list names and executive below lines of code....


powershell CrossSite Lookup










You can download this piece of code here.



Thanks,
Praveen Pandit

May 04, 2014

SharePoint 2013 auto fill people picker, auto fill people editor in application page (aspx) C#

Microsoft always comes with some new and more user friendly features in every new version. Well this client people picker (which is auto fill by user name, email or login id) new and simple control introduced in SharePoint 2013, that will save lot of time of ours.

instead of using below people picker of sharepoint 2010

<SharePoint:PeopleEditor ID="spPeoplePicker" runat="server" Width="350" SelectionSet="User" />

and setting javascript we can use  PeopleEditor to make it easy and faster for end user we can use below control in SP2013

aspx syntax :
<SharePoint:ClientPeoplePicker ValidationEnabled="true" ID="pplDemo" runat="server" VisibleSuggestions="5" AutoFillEnabled="True" AllowEmailAddresses="true" Rows="1" AllowMultipleEntities="false" CssClass="ms-long ms-spellcheck-true" Height="85px"  />



C# Code to get SPUser:
if( pplDemo.ResolvedEntities.Count > 0)
{
SPUser oUser = oWeb.SiteUsers[((PickerEntity)pplDemo.ResolvedEntities[0]).Key];

                         if (oUser != null)
                         {
                              // do your stuff.
                         }
}

C# Code to Set User to Client People Picker control:
 
 pplDemo.InitialUserAccounts = "UserEmail1";
 



Thanks,
remaining getting and saving values in SharePoint is same as earlier.

You can Share your findings or issue here.


--
Thanks,
Praveen Pandit

April 24, 2014

SharePoint how to check user, CurrentUser is in perticuler site group

You wants to check if CurrentUser or particular User / SPUser is present in specific site's permission group or not,
Usually site have three groups Visitors, Members and Owners. If you have create another group and wants to check if particular user is present is that group for some validation so you can refer below code sample,

* Assuming you have basic knowledge of SharePoint coding.



Code:
private bool UserPresentInGroup(string groupName)
        {
            bool isAdmin = false;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                { // User may not have permission to see site group or Group members....
                    using (SPSite oSite = new SPSite(strWebUrl))
                    {
                        using (SPWeb oWeb = oSite.OpenWeb())
                        {
                            SPGroup oUserGroup = oWeb.Groups[groupName];
                            foreach (SPUser item in oUserGroup.Users)
                            {
                                if (item.LoginName == currentUser.LoginName)
                                {
                                    isAdmin = true;
                                }
                            }
                        }
                    }
                });
            }
            catch (Exception exp)
            {}// Catch exception

If you wants to check user from Sites default Visitor, Member or Owner Group you can directly get group by below property
  • SPWeb.AssociatedVisitorGroup
  • SPWeb.AssociatedMemberGroup
  • SPWeb.AssociatedOwnerGroup
instead of  oUserGroup.


--
Thanks,
Praveen Pandit