Thursday 25 October 2012

How to Get Users from AD Group & Sharepoint Group ?

AD Group Users :-
**************
Add Reference from .NET tab or Browse the following location & add the dll.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\microsoft.office.workflow.tasks.dll

using Microsoft.Office.Workflow.Utility; 



Contact c = Contact.FromName("Server Name\\Group Name", Myweb);
if (c != null)
{               
Contact[] contacts = new Contact[] { c };
bool reachedMaxCount = false;
contacts = Contact.ExpandGroups(Myweb, contacts, 100, out reachedMaxCount);
}

The Above Contact Array getting memeber of the group.

****************************************************************************************
Sharepoint Group Users :-
**********************


private static void GetUsersGroups()
{ 
    using (SPSite site = new SPSite("http://sitename"))
    {

        SPWeb web = site.OpenWeb();
        SPGroupCollection groupCollection = web.SiteGroups;
                
        foreach (SPGroup group in groupCollection)
        {
            SPUserCollection userCollection = group.Users;
            Console.WriteLine("Group Name :" + group.Name+"\n");
                    
            foreach (SPUser user in userCollection)
            {
                Console.WriteLine("User Name: " + user.Name + " Email: " + user.Email + " Login: " + user.LoginName);
            }
        }
        //Iterate the owners group
        SPGroup ownerGroup = web.AssociatedOwnerGroup;              
        foreach (SPUser ownerUser in ownerGroup.Users)
        {
            Console.WriteLine("User Name: " + ownerUser.Name + " Email: " + ownerUser.Email + " Login: " + ownerUser.LoginName);
        }
    }
    Console.ReadLine();
}


 
 

how to differentiate AD Users & Groups from Sharepoint people picker programmatically ?



Add Reference from .NET tab or Browse the following location & add the dll.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\microsoft.office.workflow.tasks.dll
 

using Microsoft.Office.Workflow.Utility;


Contact c = Contact.FromName("Server Name\\Group Name", Myweb);
if (c != null)
{
string strUserType = c.PrincipalType.ToString();
}

The above PrincipalType return SecurityGroup or Users.

Friday 12 October 2012

How to Custom Validate in InfoPath MultiSelect List Box

1. You want to Add MultiSelection List Box(MSLB) & Text Box(TB) with Text Data Type.

2. Bind data Source(value & dispaly both  value name) with MSLB
   You getting like this in preview, After binding data in MSLB




3. You want to create Action rule in MSLB







4. Click Add with set field (field=TB & Value=true()).


5. Right Click on TB and Selct Text box properties


6. Click Fx Button


7. Click Insert Function & Select Count Function

8.Double Click on the "Double click to insert field" 

9. Select MSLB field from Main & Click Filter Data


10. Click Add Button

11. Don't Change 1st Dropdown as well as check, it is selected value will be MSLB from main
     2nd Dropdown will be "is equal to" & 3rd Dropdown want to select "select a field or group"


12. Select MSLB field from Secondary data source


12. Click Ok button for all window and Save it,

13. Once again click fx in TB (follow steps 5 & 6).

14. Add > 0 the like following window and click verify formula,

15.If it is showing the following message, you have done everything correctly, otherwise you want to check above steps

16. You want Create Validation & Hidden rule for TB, Before you want check TB text value will be true or false depends on the MSLB selection.

17. Validation rule condition "TB is equal to false" and type false in screen tip.
18. Hidden rule condition "TB is blank or TB is not blank" and select Hide.