Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to build a BDC Model and a custom .net connector for ActiveDirectory so that users can search for data in AD from Sharepoint as well as create lists (ie: Users list that will show users from AD) and was hoping anyone has done something similar but I can't find any material on the web. Can anyone point me in the right direction on how can this be acomplished?

share|improve this question

1 Answer 1

You can query the Active Directory using methods in the System.DirectoryServices namespace in the C# methods for your BCS model, and build it up as you would any external content type. I did something similar when first starting with BCS and it's really not any different from working with any other data source.

For an example of interacting with the namespace, here are the ReadItem and ReadList methods I wrote (as I said, it was a while ago and never intended as anything more than a learning excercise):

public static Staff ReadItem(string id)
{
    PrincipalContext _adContext = new PrincipalContext(ContextType.Domain, "developer");
    UserPrincipal u = new UserPrincipal(_adContext);
    u.SamAccountName = id;

    PrincipalSearcher search = new PrincipalSearcher(u);
    u = (UserPrincipal)search.FindOne();
    search.Dispose();

    Staff result = getUserDetail(u);

    return result;
}

public static IEnumerable<Staff> ReadList()
{
    List<Staff> result = new List<Staff>();

    PrincipalContext AD = new PrincipalContext(ContextType.Domain, "developer");
    UserPrincipal u = new UserPrincipal(AD);
    PrincipalSearcher search = new PrincipalSearcher(u);

    foreach (UserPrincipal user in search.FindAll())
    {
        Staff userdetail = getUserDetail(user);
        result.Add(userdetail);
    }

    search.Dispose();

    return result;
}

Here developer is the domain name, and getUserDetail is just a method mapping AD attributes to the properties of the Staff class.

However, before investing too much effort into going down this route, I'd advise that you consider importing the AD entities as User objects themselves with User Profile Synchronisation, as there are a lot of pieces of SharePoint that make things to do with "people" better-suited to a User object than an element of a list, and it's probably something you'd be doing anyway.

share|improve this answer
    
And how Can I get a list element in BDC ? –  Grzegorz Z Dec 7 '12 at 9:26
1  
@GrzegorzZ I don't understand your question. The BCS methods are used by BCS whenever you query the content type. You'd typically then have an external list and query that using the object model. –  TZHX Dec 7 '12 at 9:34
    
I have got a List as Esential list from CRM Microsoft Dynamics, and I want to read this list. At my Sharepoint it shows me like a List View, but I don't have got a object of column. How Can I get a internal Name for each column in this View ? –  Grzegorz Z Dec 7 '12 at 9:37
    
@TZHX - I suppose I need to update the question but I want to build a tool that will build the model dynamically by traversing ActiveDirectory's directory entries and building entities from them which can give me not only users but also computers, groups, etc. –  Adam Hobbs Dec 7 '12 at 9:40
    
@TZHX You Can read my problem here sharepoint.stackexchange.com/questions/53433/… –  Grzegorz Z Dec 7 '12 at 9:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.