473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

[imp] Active Directory Question Pls Reply

Hi,

I working on Active Directorys, and am trying to retrive some values for
certain attribute.

No problem till now, but some attributes don't have values like
Title,Second Name,etc...

When i try to compare those values with isNothing or IsDbNull its still
raising System.NullReferenceException.

How to capture this before going to exception.
I need to check its nothing then display some message else the available
value.

Code
Dim res As SearchResult
Try

If res.Properties("title")(0) Is Nothing Then
Response.Write("No title")
Else
Response.Write(res.Properties("title")(0))
End If
Catch es As Exception
Response.Write(es.ToString)
End Try

Thanks
Regards
Arvind.

Nov 15 '05 #1
7 1305
Arvind,

I would think that it would return null as well, but it might be
returning something else. Why not look in the watch window to see what a
known "null" value returns? Once you see it in your watch window, you can
code against it in your program.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Arvind P Rangan" <ar******@hotmail.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I working on Active Directorys, and am trying to retrive some values for
certain attribute.

No problem till now, but some attributes don't have values like
Title,Second Name,etc...

When i try to compare those values with isNothing or IsDbNull its still
raising System.NullReferenceException.

How to capture this before going to exception.
I need to check its nothing then display some message else the available
value.

Code
Dim res As SearchResult
Try

If res.Properties("title")(0) Is Nothing Then
Response.Write("No title")
Else
Response.Write(res.Properties("title")(0))
End If
Catch es As Exception
Response.Write(es.ToString)
End Try

Thanks
Regards
Arvind.

Nov 15 '05 #2
Cor
Hi Arvind,

I don't know the structure of values in the Active Directory, but before I
go looking for it will you try first this.
If res.Properties("title")(0) Is Nothing Then

Means normaly it does not exist.

If res.Properties("title")(0)=Nothing
means that it exist but has the default value.

If this is an SQL or Access database it is
If res.Properties("title")(0)=dbnull.value

Will you try = nothing?

Cor
Nov 15 '05 #3
Unfortunately, there is no other way than catching the System.NullReferenceException when a property doesn't exists.
Change you code to something like this:
Try
Response.Write(res.Properties("title")(0))
Catch es As Exception
Response.Write("No title")
End Try

Willy.
"Arvind P Rangan" <ar******@hotmail.com> wrote in message news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I working on Active Directorys, and am trying to retrive some values for
certain attribute.

No problem till now, but some attributes don't have values like
Title,Second Name,etc...

When i try to compare those values with isNothing or IsDbNull its still
raising System.NullReferenceException.

How to capture this before going to exception.
I need to check its nothing then display some message else the available
value.

Code
Dim res As SearchResult
Try

If res.Properties("title")(0) Is Nothing Then
Response.Write("No title")
Else
Response.Write(res.Properties("title")(0))
End If
Catch es As Exception
Response.Write(es.ToString)
End Try

Thanks
Regards
Arvind.

Nov 15 '05 #4
Hi Cor, res.Properties("title")(0) is an object, and therefore cannot "=
Nothing". It can only be "Is Nothing"

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Cor" <no*@non.com> wrote in message
news:#5*************@TK2MSFTNGP10.phx.gbl...
Hi Arvind,

I don't know the structure of values in the Active Directory, but before I
go looking for it will you try first this.
If res.Properties("title")(0) Is Nothing Then

Means normaly it does not exist.

If res.Properties("title")(0)=Nothing
means that it exist but has the default value.

If this is an SQL or Access database it is
If res.Properties("title")(0)=dbnull.value

Will you try = nothing?

Cor

Nov 15 '05 #5

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message news:OF**************@TK2MSFTNGP10.phx.gbl...
Unfortunately, there is no other way than catching the System.NullReferenceException when a property doesn't exists.
Change you code to something like this:
Try
Response.Write(res.Properties("title")(0))
Catch es As Exception
Response.Write("No title")
End Try

Willy.


Another possibility is to check if the collection contains the named property, of course there is still a chance that the
PropertyValueCollection has no item in it, but this method is preferable over the previous :-)

If res.Contains("title") Is False Then
....

Willy.
Nov 15 '05 #6
Hi Arvind,

"Arvind P Rangan" <ar******@hotmail.com> wrote in message
news:eY**************@TK2MSFTNGP12.phx.gbl...
Hi,

I working on Active Directorys, and am trying to retrive some values for
certain attribute.

No problem till now, but some attributes don't have values like
Title,Second Name,etc...

When i try to compare those values with isNothing or IsDbNull its still
raising System.NullReferenceException.

How to capture this before going to exception.
I need to check its nothing then display some message else the available
value.

Code
Dim res As SearchResult
Try

If res.Properties("title")(0) Is Nothing Then
Response.Write("No title")
Else
Response.Write(res.Properties("title")(0))
End If
Catch es As Exception
Response.Write(es.ToString)
End Try


I haven't yet had a reason to use Directory Service, but a couple of
ideas come to mind.

1. Probably a dumb question, but are you sure that the variable
"res" has been properly initialized? I notice in your code snippet it is
not, but I'm assuming you omitted it.

2. The "Properties" property of the SearchResult class returns a
ResultPropertyCollection object. The ResultPropertyCollection class has a
"Contains" method which returns true if the collection contains a certain
property, otherwise false.

...
If res.Properties.Contains("title") Then
Response.Write(res.Properties("title")(0))
Else
Response.Write("No title")
End If
...

Regards,
Dan
Nov 15 '05 #7
>When i try to compare those values with isNothing or IsDbNull its still
raising System.NullReferenceException.
How to capture this before going to exception.


Use the ".Count" property of the "Properties" property:

if (res.Properties["title"].Count > 0)
{
// do something
}

Or if that doesn't work, you can use the ".Contains" method of the
Properties:

if (res.Properties.Contains("title"))
{
// do something
}

One of the two should work, I think.

Marc

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
Hi, all, I'm trying to implement a simple plugin framework, with some unexpected results. I'm using Python 2.3.4 on Windows 2000. My script loader.py loads plugin packages from a directory (in...
9
by: Patrick | last post by:
I have an ASP.NET page that searches for someone in the corporate Active Directory. It had been working fine until recently when I changed from Basic Authentication on IIS6 back to Integrated...
10
by: Arvind P Rangan | last post by:
Hi, I working on Active Directorys, and am trying to retrive some values for certain attribute. No problem till now, but some attributes don't have values like Title,Second Name,etc... ...
14
by: rurpy | last post by:
Another Python docs problem... I was trying to use imp.find_module(). >>> imp.find_module("mymod", "./subdir") ImportError: No frozen submodule named ./subdir.mymod subdir/mymod.py...
2
by: P Webster | last post by:
We recently moved a web site that validated user credentials in Active Directory from IIS 5.1 to IIS 6, and the validation code no longer works. The web.config file is set to Windows authentication...
3
by: Lucky | last post by:
Hi guys, after long long time. i'm back again with another problem. this time i think the problem is very very interesting and i really need you help on this. i'm trying to connect to the...
3
by: MuZZy | last post by:
Hi, I'm trying to find a way to call a standard ActiveDirectory search dialog from my C# app, so i can pick a domain or computer user an dreturn it to the app. It's a search like one showing...
7
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
0
by: lairpr74 | last post by:
Hi, I got a console application that updates active directory users, the information to be updated in active directory comes from a database table. This is my problem: right now the application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.