Top Stories Photos on Yahoo! News Photos

Showing posts with label Computer. Show all posts
Showing posts with label Computer. Show all posts

Tuesday, August 26, 2008

Checked Listbox Items Iterations

You can fill you checked list box by two ways.Just simply inserting items by

chekedlistbox.items.add

and by datasource

As below........
You can also give datatable as data source.

NewUserGroup objNewUsrGrp = new NewUserGroup();
try
{
cklbUserGroups.DataSource = null;
cklbUserGroups.DataSource = objNewUsrGrp.GetUserGroups(0);
cklbUserGroups.DisplayMember = "GroupName";
cklbUserGroups.ValueMember = "GroupId";
}
catch (Exception objEx)
{
throw (objEx);
}

Iterating through selected Items/Checked Items to get Selected value....Or the ValueMember of CheckedListBox

for (int aloop = 0; aloop <= cklbUserGroups.Items.Count - 1; aloop++)
{
if (cklbUserGroups.GetItemCheckState(aloop) == CheckState.Checked)
{
cklbUserGroups.SetSelected(aloop, true);
cklbUserGroups.SelectedValue();
MessageBox.Show(cklbUserGroups.SelectedValue.ToString());
}
}
You can add any comments about this

Wednesday, August 20, 2008

Authenticate a User in Active Directory Using C#.NET

public user IsAuthenticated(string domainName, string userName, string password)
{
user userinformation = new user();
Result ReturnValue = new Result();
ReturnValue.ErrorCode = ErrorCode.UserAuthentication;


string FullName = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(this.ActiveDirectoryPath, FullName, password);
try
{
object AdEntry = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("cn");
search.PropertiesToLoad.Add("mail");
SearchResult result = search.FindOne();

if (result == null)
{
ReturnValue.IsTrue = false;
ReturnValue.Message = "Unable to authenticate " + userName + ".";
userinformation.result = ReturnValue;
return userinformation;
}

this.ActiveDirectoryPath = result.Path;

ReturnValue.IsTrue = true;
ReturnValue.Message = "Welecome " + userName + ".";
ReturnValue.UserName = (string)result.Properties["cn"][0];

userinformation.Username = ReturnValue.UserName;
userinformation.LogonUserName = userName;
if (result.Properties["mail"].Count > 0)
userinformation.Email = (string)result.Properties["mail"][0];
else
userinformation.Email = "no-email@domain.com";

}
catch (Exception ex)
{
ReturnValue.IsTrue = false;
ReturnValue.Message = ex.Message;
ReturnValue.Exception = ex.Message;
}

userinformation.result = ReturnValue;

return userinformation;
}