DirectoryEntry.Exists Method

DirectoryEntry.Exists Method

Post by Michael Hetric » Thu, 05 Dec 2002 13:38:48



I would like to test to see if a specific user exists.  Reading the
documentation at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfSystemDirectoryServices.asp, there is a method Exists().  I am unable
to use it.

I receive a compile error of "No overload for method 'Exists' takes '0'
arguments" when trying this:
if (user.Exists())

{

         // Do this...

Quote:}

else

{

        //Do that

Quote:}

I am able to read from AD otherwise.  Thanks for any information.

Mike

 
 
 

DirectoryEntry.Exists Method

Post by Garet » Thu, 05 Dec 2002 23:21:52


Have you tried omitting the brackets?  I believe VB has
two different, distinct ways of calling methods:

Call user.exists()

or

user.exists

Hope this helps

Gareth

Quote:>-----Original Message-----
>I would like to test to see if a specific user exists.  
Reading the
>documentation at
>http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/cpref/html/
Quote:>frlrfSystemDirectoryServices.asp, there is a method Exists
().  I am unable
>to use it.

>I receive a compile error of "No overload for

method 'Exists' takes '0'
Quote:>arguments" when trying this:
>if (user.Exists())

>{

>         // Do this...

>}

>else

>{

>        //Do that

>}

>I am able to read from AD otherwise.  Thanks for any
information.

>Mike

>.


 
 
 

DirectoryEntry.Exists Method

Post by Joe Kapla » Fri, 06 Dec 2002 00:18:52


Exists is a shared (static) method on the DirectoryEntry
class.  You should call it like this:

If DirectoryEntry.Exists("LDAP://<your object DN>") Then
'... do something here
End If

It does not work on an instance of a DirectoryEntry.

If you have already instantiated a DirectoryEntry object
and just want to force the bind operation in order to see
if the object exists, then you just need to call one of
the properties or methods that will force a bind.  Doing
something like this will work:

Dim myEntry as New DirectoryEntry("LDAP://<your object
DN>")

Try
   Debug.WriteLine(myEntry.NativeGuid)
   'or perhaps
   myEntry.RefreshCache()
Catch e as System.Runtime.InteropServices.COMException
   'if the DN does not exist or is an invalid syntax
   'e.ErrorCode will equal -2147016656 (no such object)
   'or -2147016654 (invalid syntax)
   'you can test for either of these results explicitly
   'if you want know the exact reason why the object
   'wasn't found.  The "no such object" error code is
   'probably the one you are most interested in.
End Try

I hope that helps.

Joe K.

Quote:>-----Original Message-----
>I would like to test to see if a specific user exists.  
Reading the
>documentation at
>http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/cpref/html/
Quote:>frlrfSystemDirectoryServices.asp, there is a method

Exists().  I am unable
Quote:>to use it.

>I receive a compile error of "No overload for

method 'Exists' takes '0'
Quote:>arguments" when trying this:
>if (user.Exists())

>{

>         // Do this...

>}

>else

>{

>        //Do that

>}

>I am able to read from AD otherwise.  Thanks for any
information.

>Mike

>.