Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Interrogation annuaire LDAP

4 réponses
Avatar
Denis
Bonjour,

Je ne connecte à un annuaire LDAP avec

DirectoryEntry annuaire = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher(annuaire);

puis je recherche une personne ainsi

searcher.Filter = "(anr=" + name + ")";

Jusque là, ça marche.


Maintenant, comment obtenir la liste de toutes les propriétés disponibles de
mon annuaire ?

Aloha, 2nis

4 réponses

Avatar
Faust
faut faire un findall/findone
puis un foreach sur les résultats

public class MySample
{
public static void Main()
{
string myLDAPPath = "";
try
{
// Create a 'DirectoryEntry' object to search.
Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
myLDAPPath = Console.ReadLine();
DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);

DirectorySearcher myDirectorySearcher new
DirectorySearcher(mySearchRoot);

// Get the first entry of the search.
SearchResult mySearchResult = myDirectorySearcher.FindOne();
if ( mySearchResult != null )
{
// Get the 'DirectoryEntry' that corresponds to
'mySearchResult'.
DirectoryEntry myDirectoryEntry
mySearchResult.GetDirectoryEntry();
Console.WriteLine("nThe name of the 'myDirectoryEntry' " +
"directory entry that corresponds to the
" +
"'mySearchResult' search result is :
{0}n",
myDirectoryEntry.Name);

string mySearchResultPath = mySearchResult.Path;
Console.WriteLine("The path for the 'mySearchResult' search
"
+ "result is : {0}n",
mySearchResultPath);

// Get the properties of the 'mySearchResult'.
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
Console.WriteLine("The properties of the " +
"'mySearchResult' are :");
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
}
else
{
Console.WriteLine("The '" + myLDAPPath + "' path not
found.");
}
}
catch(Exception e)
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
Console.WriteLine("Exception : " + e.Message);
}
}
}


/_Denis_ a prétendu/ :
Bonjour,



Je ne connecte à un annuaire LDAP avec



DirectoryEntry annuaire = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher(annuaire);



puis je recherche une personne ainsi



searcher.Filter = "(anr=" + name + ")";



Jusque là, ça marche.



Maintenant, comment obtenir la liste de toutes les propriétés disponibles de
mon annuaire ?



Aloha, 2nis



--
Faust
"Une âme en peine peut en cacher une autre"
Avatar
Denis
Ce n'est pas tout à fait cela que je recherche

Ce que je recherche, c'est la structure de la "fiche" d'une personne pour
recuperer son identifiant, nom, prenom, téléphone, adresse mail,
etc.....(j'ai 43 propriétés dans "annuaire.Properties") C'est le nom de ces
43 propriétés.

aloha, 2nis

"Faust" wrote:

faut faire un findall/findone
puis un foreach sur les résultats

public class MySample
{
public static void Main()
{
string myLDAPPath = "";
try
{
// Create a 'DirectoryEntry' object to search.
Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
myLDAPPath = Console.ReadLine();
DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);

DirectorySearcher myDirectorySearcher > new
DirectorySearcher(mySearchRoot);

// Get the first entry of the search.
SearchResult mySearchResult = myDirectorySearcher.FindOne();
if ( mySearchResult != null )
{
// Get the 'DirectoryEntry' that corresponds to
'mySearchResult'.
DirectoryEntry myDirectoryEntry >
mySearchResult.GetDirectoryEntry();
Console.WriteLine("nThe name of the 'myDirectoryEntry' " +
"directory entry that corresponds to the
" +
"'mySearchResult' search result is :
{0}n",
myDirectoryEntry.Name);

string mySearchResultPath = mySearchResult.Path;
Console.WriteLine("The path for the 'mySearchResult' search
"
+ "result is : {0}n",
mySearchResultPath);

// Get the properties of the 'mySearchResult'.
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
Console.WriteLine("The properties of the " +
"'mySearchResult' are :");
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
}
else
{
Console.WriteLine("The '" + myLDAPPath + "' path not
found.");
}
}
catch(Exception e)
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
Console.WriteLine("Exception : " + e.Message);
}
}
}


/_Denis_ a prétendu/ :
> Bonjour,

> Je ne connecte à un annuaire LDAP avec

> DirectoryEntry annuaire = new DirectoryEntry();
> DirectorySearcher searcher = new DirectorySearcher(annuaire);

> puis je recherche une personne ainsi

> searcher.Filter = "(anr=" + name + ")";

> Jusque là, ça marche.

> Maintenant, comment obtenir la liste de toutes les propriétés disponibles de
> mon annuaire ?

> Aloha, 2nis

--
Faust
"Une âme en peine peut en cacher une autre"





Avatar
Faust
avec avec la boucle
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in
myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}

tu as et le nom et la valeur

donc, dans un premier temps, tu execute cette boucle pour toi en test,
tu repère les valeurs qui t'interressent puis voilà

je suis présentement aussi en train de me battre avec le LDAP, et une
chose que je constate, c'est que manifestement c'est un peu l'anarchie
au niveau des noms de propriétés (on met, on met pas, on change le nom,
etc)

/_Denis_ a émis l'idée suivante/ :
Ce n'est pas tout à fait cela que je recherche



Ce que je recherche, c'est la structure de la "fiche" d'une personne pour
recuperer son identifiant, nom, prenom, téléphone, adresse mail,
etc.....(j'ai 43 propriétés dans "annuaire.Properties") C'est le nom de ces
43 propriétés.



aloha, 2nis



"Faust" wrote:



faut faire un findall/findone
puis un foreach sur les résultats

public class MySample
{
public static void Main()
{
string myLDAPPath = "";
try
{
// Create a 'DirectoryEntry' object to search.
Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
myLDAPPath = Console.ReadLine();
DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);

DirectorySearcher myDirectorySearcher >> new
DirectorySearcher(mySearchRoot);

// Get the first entry of the search.
SearchResult mySearchResult = myDirectorySearcher.FindOne();
if ( mySearchResult != null )
{
// Get the 'DirectoryEntry' that corresponds to
'mySearchResult'.
DirectoryEntry myDirectoryEntry >>
mySearchResult.GetDirectoryEntry();
Console.WriteLine("nThe name of the 'myDirectoryEntry' " +
"directory entry that corresponds to the
" +
"'mySearchResult' search result is :
{0}n",
myDirectoryEntry.Name);

string mySearchResultPath = mySearchResult.Path;
Console.WriteLine("The path for the 'mySearchResult' search
"
+ "result is : {0}n",
mySearchResultPath);

// Get the properties of the 'mySearchResult'.
ResultPropertyCollection myResultPropColl;
myResultPropColl = mySearchResult.Properties;
Console.WriteLine("The properties of the " +
"'mySearchResult' are :");
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}
}
else
{
Console.WriteLine("The '" + myLDAPPath + "' path not
found.");
}
}
catch(Exception e)
{
Console.WriteLine("The '" + myLDAPPath + "' path not found.");
Console.WriteLine("Exception : " + e.Message);
}
}
}

/_Denis_ a prétendu/ :
Bonjour,



Je ne connecte à un annuaire LDAP avec
DirectoryEntry annuaire = new DirectoryEntry();
DirectorySearcher searcher = new DirectorySearcher(annuaire);
puis je recherche une personne ainsi
searcher.Filter = "(anr=" + name + ")";
Jusque là, ça marche.



Maintenant, comment obtenir la liste de toutes les propriétés disponibles
de mon annuaire ?



Aloha, 2nis



--
Faust
"Une âme en peine peut en cacher une autre"






--
Faust
"Une âme en peine peut en cacher une autre"
Avatar
Denis
Effectivement, j'ai bien toutes sortes de propriétés et effectivement, ça
ressemble à un vrai foutoir !!
En plus, je me rends compte que les infos que je récupère sont les infos du
contrôleur de domaine, pas celle du LDAP !


"Faust" wrote:

avec avec la boucle
foreach( string myKey in myResultPropColl.PropertyNames)
{
string tab = " ";
Console.WriteLine(myKey + " = ");
foreach( Object myCollection in
myResultPropColl[myKey])
{
Console.WriteLine(tab + myCollection);
}
}

tu as et le nom et la valeur

donc, dans un premier temps, tu execute cette boucle pour toi en test,
tu repère les valeurs qui t'interressent puis voilà

je suis présentement aussi en train de me battre avec le LDAP, et une
chose que je constate, c'est que manifestement c'est un peu l'anarchie
au niveau des noms de propriétés (on met, on met pas, on change le nom,
etc)

/_Denis_ a émis l'idée suivante/ :
> Ce n'est pas tout à fait cela que je recherche

> Ce que je recherche, c'est la structure de la "fiche" d'une personne pour
> recuperer son identifiant, nom, prenom, téléphone, adresse mail,
> etc.....(j'ai 43 propriétés dans "annuaire.Properties") C'est le nom de ces
> 43 propriétés.

> aloha, 2nis

> "Faust" wrote:

>> faut faire un findall/findone
>> puis un foreach sur les résultats
>>
>> public class MySample
>> {
>> public static void Main()
>> {
>> string myLDAPPath = "";
>> try
>> {
>> // Create a 'DirectoryEntry' object to search.
>> Console.WriteLine("Enter the path ( Ex : 'LDAP://MyServer')");
>> myLDAPPath = Console.ReadLine();
>> DirectoryEntry mySearchRoot = new DirectoryEntry(myLDAPPath);
>>
>> DirectorySearcher myDirectorySearcher > >> new
>> DirectorySearcher(mySearchRoot);
>>
>> // Get the first entry of the search.
>> SearchResult mySearchResult = myDirectorySearcher.FindOne();
>> if ( mySearchResult != null )
>> {
>> // Get the 'DirectoryEntry' that corresponds to
>> 'mySearchResult'.
>> DirectoryEntry myDirectoryEntry > >>
>> mySearchResult.GetDirectoryEntry();
>> Console.WriteLine("nThe name of the 'myDirectoryEntry' " +
>> "directory entry that corresponds to the
>> " +
>> "'mySearchResult' search result is :
>> {0}n",
>> myDirectoryEntry.Name);
>>
>> string mySearchResultPath = mySearchResult.Path;
>> Console.WriteLine("The path for the 'mySearchResult' search
>> "
>> + "result is : {0}n",
>> mySearchResultPath);
>>
>> // Get the properties of the 'mySearchResult'.
>> ResultPropertyCollection myResultPropColl;
>> myResultPropColl = mySearchResult.Properties;
>> Console.WriteLine("The properties of the " +
>> "'mySearchResult' are :");
>> foreach( string myKey in myResultPropColl.PropertyNames)
>> {
>> string tab = " ";
>> Console.WriteLine(myKey + " = ");
>> foreach( Object myCollection in myResultPropColl[myKey])
>> {
>> Console.WriteLine(tab + myCollection);
>> }
>> }
>> }
>> else
>> {
>> Console.WriteLine("The '" + myLDAPPath + "' path not
>> found.");
>> }
>> }
>> catch(Exception e)
>> {
>> Console.WriteLine("The '" + myLDAPPath + "' path not found.");
>> Console.WriteLine("Exception : " + e.Message);
>> }
>> }
>> }
>>
>> /_Denis_ a prétendu/ :
>>> Bonjour,
>>
>>> Je ne connecte à un annuaire LDAP avec
>>> DirectoryEntry annuaire = new DirectoryEntry();
>>> DirectorySearcher searcher = new DirectorySearcher(annuaire);
>>> puis je recherche une personne ainsi
>>> searcher.Filter = "(anr=" + name + ")";
>>> Jusque là, ça marche.
>>
>>> Maintenant, comment obtenir la liste de toutes les propriétés disponibles
>>> de mon annuaire ?
>>
>>> Aloha, 2nis
>>
>> --
>> Faust
>> "Une âme en peine peut en cacher une autre"
>>

--
Faust
"Une âme en peine peut en cacher une autre"