Monday, August 26, 2013

c# autoamtic properties with null value

c# autoamtic properties with null value

I have following Problem.
My Auto Properties SearchedObjClass,SearchedProp ,SearchedPropValue result
into null value although i assigned values in main program to them: Can
some one help me to find out what the Problem is:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.DirectoryServices
namespace Server_Management_Tool
{
class ADClassNew
{
public static DirectoryEntry createDirectoryEntry()
{
string ldapusername = "Username";
string ldapuserpass = "Password";
using (DirectoryEntry root =new DirectoryEntry())
{
ADClassNew adclass = new ADClassNew();
root.Path = adclass.LdapPath;
root.Username = ldapusername;
root.Password = ldapuserpass;
root.AuthenticationType = AuthenticationTypes.Secure;
return root;
}
}
public string SearchedObjClass { get; set; }
public string SearchedProp { get; set; }
public string SearchedPropValue { get; set; }
public string LdapPath { get; set; }
public StringCollection LoadProperties { get; set; }
public SearchResult searchDirectory()
{
DirectoryEntry searchEntry =
ADClassNew.createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher();
search.SearchRoot = searchEntry;
ADClassNew adclassnew = new ADClassNew();
//string _searchedObjClass = SearchedObjClass;
//string _searchedProp = SearchedProp;
//string _searchedPropValue = SearchedPropValue;
search.Filter =
string.Format("(&(ObjectClass={0})({1}={2}))",
adclassnew.SearchedObjClass, adclassnew.SearchedProp,
adclassnew.SearchedPropValue);
//search.Filter = "(&(objectClass=user)(cn=administrator))";
search.PropertiesToLoad.Add("memberof");
SearchResult result = search.FindOne();
return result;
}
}
}
namespace Server_Management_Tool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ADClassNew adclassnew = new ADClassNew();
adclassnew.LdapPath = "LDAP://MyDomain";
adclassnew.SearchedObjClass = "User";
adclassnew.SearchedProp = "Displayname";
adclassnew.SearchedPropValue = "administrator";
}
}
}

No comments:

Post a Comment