473,395 Members | 1,568 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,395 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 20 '05 #1
10 1142
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 20 '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 20 '05 #3
Cor,
Its all the same
I have tried all those option whichu have mentioned.

DBNull.value is not possible as its not from DB.
I need to some how convert the value to object and then check it.

Thanks
arvind
Cor wrote:
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 20 '05 #4
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 20 '05 #5
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 20 '05 #6
Cor
Sorry Arvind,

I did not read it well.

To catch if the property not exist, I think you can make something like
\\\
If res.Properties("Name").Count > 0 Then
response.write(res.Properties("Name")(0).ToString)
End If
///
I hoope this will help a little bit?
Cor

Nov 20 '05 #7

"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 20 '05 #8
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 20 '05 #9
>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 20 '05 #10
Thanks Everyone.

It worked fine with properties.contains("") as its an object we can
check if it exists or not.

Thanks a lot
I can't name who all but everyone who has given me the answer.

Be online for further enquires.
Arvind.

Marc Scheuner [MVP ADSI] wrote:
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 20 '05 #11

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...
7
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... ...
1
by: Stephan Bour | last post by:
Hi, I am trying to authenticate form users using a local Active Directory server and I get the following error message at compile: Compiler Error Message: CS0029: Cannot implicitly convert type...
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.