problem in this block of code provided can anyone correct thisblockof code

Discussion in 'ASP .Net Web Services' started by Dhananjay, Mar 26, 2009.

  1. Dhananjay

    Dhananjay Guest

    hi

    I am facing problem in this block of code provided below can you
    please help me to get solved! the problem gets executed when foreach
    block of code gets executed to get a list of items and values from the
    Active Directory list. It doesn't return anything . it should return
    the userIfo with values .Please help me to resolve this issue.

    Thanks in advance !



    ======================================================================================================

    private static System.Collections.Specialized.NameValueCollection
    userPropertyKeys = null;
    public User GetUserInfoFromAD(string username)
    {

    User userInfo = new User();

    string str = username;
    DirectoryEntry myldapconnection = createDirectoryEntry();

    DirectorySearcher search = new DirectorySearcher(myldapconnection);
    search.Filter = "(cn=" + str + ")";

    SearchResult result = search.FindOne();


    foreach (string ldapfield in fields.PropertyNames)
    {

    if (fields != null && userPropertyKeys.Keys.Count > 0)
    {

    for (int i = 0; i < userPropertyKeys.Keys.Count - 1; i++)
    {

    string userPropertyValue = userPropertyKeys.Keys;if (!
    string.IsNullOrEmpty(userPropertyValue) && result.Properties
    [userPropertyValue].Count > 0)
    {

    switch (userPropertyKeys.Keys)
    {

    case "name":

    if (!userInfo.UserName.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //userInfo = true;

    userInfo.UserName = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "Password":

    if (!userInfo.Password.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //userInfo = true;

    userInfo.Password = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "firstname":

    if (!userInfo.FirstName.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.FirstName = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "lastname":

    if (!userInfo.LastName.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.LastName = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "displayName":

    if (!userInfo.LoginName.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.LoginName = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "country":

    if (!userInfo.Country.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.Country = result.Properties[userPropertyValue][0].ToString();

    }

    break;
    case "state":

    if (!userInfo.State.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.State = result.Properties[userPropertyValue][0].ToString();

    }

    break;
    case "zip":

    if (!userInfo.Zip.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.Zip = result.Properties[userPropertyValue][0].ToString();

    }

    break;
    case "mail":

    if (!userInfo.Email.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.Email = result.Properties[userPropertyValue][0].ToString();

    }

    break;
    case "telephoneNumber":

    if (!userInfo_OfficePhone.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo_OfficePhone = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "mobilePhone":

    if (!userInfo.MobilePhone.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.MobilePhone = result.Properties[userPropertyValue][0].ToString
    ();

    }

    break;
    case "mobileCareer":

    if (!userInfo.MobileCarrier.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.MobileCarrier = result.Properties[userPropertyValue]
    [0].ToString();

    }

    break;
    case "active":

    if (!userInfo.Active.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.Active = (int)result.Properties[userPropertyValue][0];
    }

    break;
    case "creation_date":

    if (!userInfo.CreationDate.Equals(result.Properties[userPropertyValue]
    [0].ToString()))
    {

    //username = true;

    userInfo.CreationDate = (DateTime)result.Properties[userPropertyValue]
    [0];
    }

    break;
    }

    }

    }



    }


    }return userInfo;
    }
     
    Dhananjay, Mar 26, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page