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


D

Dhananjay

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;
}
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top