Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Wed, 27 Apr 2005 18:50:42 +1200,    group: microsoft.public.platformsdk.active.directory        back       


officelocation property from asp.net   
Hi,

I am attempting to retrive a list of users from Ad via asp.net and display 
them on a page.
All is going well and I am returning all my desired fields apart from one 
that is called "officeLocations"
The code I am using is below.
Can anybody please shed any light on how I retrieve this property.

getstring is a method that simple checks if the object is null before 
attempting to convert it to a string.

cheers

martin.

foreach(System.DirectoryServices.SearchResult resEnt in 
mySearcher.FindAll())
    {

     counter++;
     try
     {
      System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
      DisplayName = 
getString(de.Properties["DisplayName"].Value).ToString();
      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
      //Title = getString(de.Properties["Title"].Value).ToString();
      UserName = 
getString(de.Properties["sAMAccountName"].Value).ToString();
      FirstName = getString(de.Properties["GivenName"].Value).ToString();
      LastName = getString(de.Properties["sn"].Value).ToString();
      //Initials = getString(de.Properties["Initials"].Value).ToString();
      Company = getString(de.Properties["Company"].Value).ToString();
      Department = getString(de.Properties["Department"].Value).ToString();
      TelephoneNumber = 
getString(de.Properties["TelephoneNumber"].Value).ToString();
      OfficeLocations = 
getString(de.Properties["OfficeLocations"].Value).ToString(); 
<<<<<<<<<<<<Can't get this.............
date: Wed, 27 Apr 2005 18:50:42 +1200   author:   Martin

Re: officelocation property from asp.net   
officeLocations isn't in the schema, so that won't work.  I'm not sure 
exactly what attribute you want, but perhaps it is 
physicalDeliveryOfficeName?

Two other things while we are looking at your code:
 - Add the attributes you want back from AD to the PropertiesToLoad and get 
the values directly from the SearchResult instead of using the 
DirectoryEntry.  It should speed up your code by as much as an order of 
magnitude.
 - Make sure you enclose all of your IDisposable objects (DirectoryEntry, 
DirectorySearcher, SearchResultCollection) in "using" blocks so they get 
disposed.  You want to prevent possible memory leaks, especially in 
long-runnng processes like web apps.

Joe K.

"Martin"  wrote in message 
news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I am attempting to retrive a list of users from Ad via asp.net and display 
> them on a page.
> All is going well and I am returning all my desired fields apart from one 
> that is called "officeLocations"
> The code I am using is below.
> Can anybody please shed any light on how I retrieve this property.
>
> getstring is a method that simple checks if the object is null before 
> attempting to convert it to a string.
>
> cheers
>
> martin.
>
> foreach(System.DirectoryServices.SearchResult resEnt in 
> mySearcher.FindAll())
>    {
>
>     counter++;
>     try
>     {
>      System.DirectoryServices.DirectoryEntry 
> de=resEnt.GetDirectoryEntry();
>      DisplayName = 
> getString(de.Properties["DisplayName"].Value).ToString();
>      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
>      //Title = getString(de.Properties["Title"].Value).ToString();
>      UserName = 
> getString(de.Properties["sAMAccountName"].Value).ToString();
>      FirstName = getString(de.Properties["GivenName"].Value).ToString();
>      LastName = getString(de.Properties["sn"].Value).ToString();
>      //Initials = getString(de.Properties["Initials"].Value).ToString();
>      Company = getString(de.Properties["Company"].Value).ToString();
>      Department = getString(de.Properties["Department"].Value).ToString();
>      TelephoneNumber = 
> getString(de.Properties["TelephoneNumber"].Value).ToString();
>      OfficeLocations = 
> getString(de.Properties["OfficeLocations"].Value).ToString(); 
> <<<<<<<<<<<<Can't get this.............
>
date: Thu, 28 Apr 2005 00:38:18 -0500   author:   Joe Kaplan \(MVP - ADSI\)

Re: officelocation property from asp.net   
Hi Joe,

Thanks a lot for the reply.
I have taken your comments about code efficiency on board and will implement 
all of you suggestions.

The code I am using is running on a windows 2003 server.
I have been assured by our network people that the "OfficeLocations" 
property does exist in the schema and they insist that they have not added 
this property to the schema.
The code below (VB script) does grab this property, so it can be obtained 
from vb script but I can't find how to get it from .net.

However from what I can gather about this property, it is not returned as a 
single value, it is returnd as a "C struct" becuase there can be more that 
one office location assosiated with a user!!  so i guess it has to be 
assosited with some sort of array object..

If  you could shed any more light on this for me then I would appreciate it.

one interesting point is that the VB Script code below returns the users 
full name as  "FullName" where as my .net code returns the same property as 
"DisplayName" as maybe there is some discrepancy in naming.


cheers

martin.




 =================start code snippet==================================
Dim cont
Dim usr
Dim office
Dim searching, searchName, searchDept, searchOffice

' LDAP bind and open user OU

Set cont = GetObject("LDAP://OU=mudomain users ,DC=mydomain,DC=local")

' Check for search criterium
If (Len(Request.QueryString("name")) > 0 Or Len(Request.QueryString("dept")) 
 > 0 Or Len(Request.QueryString("office")) > 0) Then
 searching = true
Else
 searching = false
End If
searchName = Request.QueryString("name")
searchDept = Request.QueryString("dept")
searchOffice = Request.QueryString("office")

' Enumerate through the users
row = 0
For Each obj In cont
 Set usr = cont.GetObject("user", obj.Name)

 ' safely grab the office location - this throws an exception
 ' if the field is not populated, so must be handled gracefully
 office = ""
 On Error Resume Next
 office = usr.OfficeLocations 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 If searching = false Or (InStr(1, usr.FullName, searchName, 1) > 0 And 
InStr(1, usr.Department, searchDept, 1) > 0 And InStr(1, office, 
searchOffice, 1) > 0) Then
%>
  <tr>
   <td class="row">
    <a href="detail.asp?user=<%=obj.Name%>"><%=usr.FullName%></a>
   </td>
   <td class="row">
    <%=usr.Department%> 
   </td>
   <td class="row">
    <%=office%> 
   </td>
   <td class="row">
    <%=usr.TelephoneNumber%> 
   </td>
  </tr>
<%
 End If
Next
%>
 =================End code snippet==================================







"Joe Kaplan (MVP - ADSI)"  wrote 
in message news:%23vA%237R7SFHA.3308@TK2MSFTNGP14.phx.gbl...
> officeLocations isn't in the schema, so that won't work.  I'm not sure 
> exactly what attribute you want, but perhaps it is 
> physicalDeliveryOfficeName?
>
> Two other things while we are looking at your code:
> - Add the attributes you want back from AD to the PropertiesToLoad and get 
> the values directly from the SearchResult instead of using the 
> DirectoryEntry.  It should speed up your code by as much as an order of 
> magnitude.
> - Make sure you enclose all of your IDisposable objects (DirectoryEntry, 
> DirectorySearcher, SearchResultCollection) in "using" blocks so they get 
> disposed.  You want to prevent possible memory leaks, especially in 
> long-runnng processes like web apps.
>
> Joe K.
>
> "Martin"  wrote in message 
> news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
>> Hi,
>>
>> I am attempting to retrive a list of users from Ad via asp.net and 
>> display them on a page.
>> All is going well and I am returning all my desired fields apart from one 
>> that is called "officeLocations"
>> The code I am using is below.
>> Can anybody please shed any light on how I retrieve this property.
>>
>> getstring is a method that simple checks if the object is null before 
>> attempting to convert it to a string.
>>
>> cheers
>>
>> martin.
>>
>> foreach(System.DirectoryServices.SearchResult resEnt in 
>> mySearcher.FindAll())
>>    {
>>
>>     counter++;
>>     try
>>     {
>>      System.DirectoryServices.DirectoryEntry 
>> de=resEnt.GetDirectoryEntry();
>>      DisplayName = 
>> getString(de.Properties["DisplayName"].Value).ToString();
>>      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
>>      //Title = getString(de.Properties["Title"].Value).ToString();
>>      UserName = 
>> getString(de.Properties["sAMAccountName"].Value).ToString();
>>      FirstName = getString(de.Properties["GivenName"].Value).ToString();
>>      LastName = getString(de.Properties["sn"].Value).ToString();
>>      //Initials = getString(de.Properties["Initials"].Value).ToString();
>>      Company = getString(de.Properties["Company"].Value).ToString();
>>      Department = 
>> getString(de.Properties["Department"].Value).ToString();
>>      TelephoneNumber = 
>> getString(de.Properties["TelephoneNumber"].Value).ToString();
>>      OfficeLocations = 
>> getString(de.Properties["OfficeLocations"].Value).ToString(); 
>> <<<<<<<<<<<<Can't get this.............
>>
>
>
date: Fri, 29 Apr 2005 09:00:54 +1200   author:   Martin

Re: officelocation property from asp.net   
There is a confusion in terms here.  OfficeLocations is an ADSI property on 
the IADsUser interface, but it isn't an actual attribute in AD.  You can 
verify this for yourself by pulling up ldp.exe and doing a search in the 
schema container for an object with ldapDisplayName=OfficeLocations.  You 
won't find it.  Additionally, if you pull up any user in your AD with 
ldp.exe or ADSI Edit, you won't see OfficeLocations in the returned result.

I can confirm with certainty that the actual AD attribute name is 
physicalDeliveryOfficeName.  I just checked the MS source code to be sure.

While it is possible to call the IADsUser property methods from .NET (link 
here: ), you wouldn't want to do it this way because it forces you to bind 
to the object.

Regarding the question about arrays, attributes in AD can be single or 
multivalued.  In order to implement a general API for handling both, they 
are all treated as multi-valued in S.DS.

Thus, the correct pattern for dealing with this in C# would go something 
like:

searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
SearchResultCollection results;
using (results = searcher.FindAll())
{
foreach(SearchResult result in results)
{
string office;
if (result.Properties.Contains("physicalDeliveryOfficeName"))
    office = (string) result.Properties["physicalDeliveryOfficeName"][0];
}
}

HTH,

Joe K.


"Martin"  wrote in message 
news:e7WMgVDTFHA.3308@TK2MSFTNGP14.phx.gbl...
> Hi Joe,
>
> Thanks a lot for the reply.
> I have taken your comments about code efficiency on board and will 
> implement all of you suggestions.
>
> The code I am using is running on a windows 2003 server.
> I have been assured by our network people that the "OfficeLocations" 
> property does exist in the schema and they insist that they have not added 
> this property to the schema.
> The code below (VB script) does grab this property, so it can be obtained 
> from vb script but I can't find how to get it from .net.
>
> However from what I can gather about this property, it is not returned as 
> a single value, it is returnd as a "C struct" becuase there can be more 
> that one office location assosiated with a user!!  so i guess it has to be 
> assosited with some sort of array object..
>
> If  you could shed any more light on this for me then I would appreciate 
> it.
>
> one interesting point is that the VB Script code below returns the users 
> full name as  "FullName" where as my .net code returns the same property 
> as "DisplayName" as maybe there is some discrepancy in naming.
>
>
> cheers
>
> martin.
>
>
>
>
> =================start code snippet==================================
> Dim cont
> Dim usr
> Dim office
> Dim searching, searchName, searchDept, searchOffice
>
> ' LDAP bind and open user OU
>
> Set cont = GetObject("LDAP://OU=mudomain users ,DC=mydomain,DC=local")
>
> ' Check for search criterium
> If (Len(Request.QueryString("name")) > 0 Or 
> Len(Request.QueryString("dept"))
> > 0 Or Len(Request.QueryString("office")) > 0) Then
> searching = true
> Else
> searching = false
> End If
> searchName = Request.QueryString("name")
> searchDept = Request.QueryString("dept")
> searchOffice = Request.QueryString("office")
>
> ' Enumerate through the users
> row = 0
> For Each obj In cont
> Set usr = cont.GetObject("user", obj.Name)
>
> ' safely grab the office location - this throws an exception
> ' if the field is not populated, so must be handled gracefully
> office = ""
> On Error Resume Next
> office = usr.OfficeLocations 
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
> If searching = false Or (InStr(1, usr.FullName, searchName, 1) > 0 And 
> InStr(1, usr.Department, searchDept, 1) > 0 And InStr(1, office, 
> searchOffice, 1) > 0) Then
> %>
>  <tr>
>   <td class="row">
>    <a href="detail.asp?user=<%=obj.Name%>"><%=usr.FullName%></a>
>   </td>
>   <td class="row">
>    <%=usr.Department%> 
>   </td>
>   <td class="row">
>    <%=office%> 
>   </td>
>   <td class="row">
>    <%=usr.TelephoneNumber%> 
>   </td>
>  </tr>
> <%
> End If
> Next
> %>
> =================End code snippet==================================
>
>
>
>
>
>
>
> "Joe Kaplan (MVP - ADSI)"  wrote 
> in message news:%23vA%237R7SFHA.3308@TK2MSFTNGP14.phx.gbl...
>> officeLocations isn't in the schema, so that won't work.  I'm not sure 
>> exactly what attribute you want, but perhaps it is 
>> physicalDeliveryOfficeName?
>>
>> Two other things while we are looking at your code:
>> - Add the attributes you want back from AD to the PropertiesToLoad and 
>> get the values directly from the SearchResult instead of using the 
>> DirectoryEntry.  It should speed up your code by as much as an order of 
>> magnitude.
>> - Make sure you enclose all of your IDisposable objects (DirectoryEntry, 
>> DirectorySearcher, SearchResultCollection) in "using" blocks so they get 
>> disposed.  You want to prevent possible memory leaks, especially in 
>> long-runnng processes like web apps.
>>
>> Joe K.
>>
>> "Martin"  wrote in message 
>> news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
>>> Hi,
>>>
>>> I am attempting to retrive a list of users from Ad via asp.net and 
>>> display them on a page.
>>> All is going well and I am returning all my desired fields apart from 
>>> one that is called "officeLocations"
>>> The code I am using is below.
>>> Can anybody please shed any light on how I retrieve this property.
>>>
>>> getstring is a method that simple checks if the object is null before 
>>> attempting to convert it to a string.
>>>
>>> cheers
>>>
>>> martin.
>>>
>>> foreach(System.DirectoryServices.SearchResult resEnt in 
>>> mySearcher.FindAll())
>>>    {
>>>
>>>     counter++;
>>>     try
>>>     {
>>>      System.DirectoryServices.DirectoryEntry 
>>> de=resEnt.GetDirectoryEntry();
>>>      DisplayName = 
>>> getString(de.Properties["DisplayName"].Value).ToString();
>>>      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
>>>      //Title = getString(de.Properties["Title"].Value).ToString();
>>>      UserName = 
>>> getString(de.Properties["sAMAccountName"].Value).ToString();
>>>      FirstName = getString(de.Properties["GivenName"].Value).ToString();
>>>      LastName = getString(de.Properties["sn"].Value).ToString();
>>>      //Initials = getString(de.Properties["Initials"].Value).ToString();
>>>      Company = getString(de.Properties["Company"].Value).ToString();
>>>      Department = 
>>> getString(de.Properties["Department"].Value).ToString();
>>>      TelephoneNumber = 
>>> getString(de.Properties["TelephoneNumber"].Value).ToString();
>>>      OfficeLocations = 
>>> getString(de.Properties["OfficeLocations"].Value).ToString(); 
>>> <<<<<<<<<<<<Can't get this.............
>>>
>>
>>
>
>
date: Thu, 28 Apr 2005 17:06:52 -0500   author:   Joe Kaplan \(MVP - ADSI\)

Re: officelocation property from asp.net   
Hi joe,

many thanks again for the reply.
I will propabally get a chance to try this over the weekend and I will let 
you know how it goes.

regarding your email,
how did you manage to "check the MS source code to be sure"
is this something that I can do and is this source code publically 
availible????

also you refer to a link

> While it is possible to call the IADsUser property methods from .NET (link 
> here: ), you wouldn't want to do it this way because it forces you to bind 
> to the object.

is it possible to let me know this link.

again, many thanks for your help.

cheers

martin




"Joe Kaplan (MVP - ADSI)"  wrote 
in message news:etI8W6DTFHA.3280@TK2MSFTNGP09.phx.gbl...
> There is a confusion in terms here.  OfficeLocations is an ADSI property 
> on the IADsUser interface, but it isn't an actual attribute in AD.  You 
> can verify this for yourself by pulling up ldp.exe and doing a search in 
> the schema container for an object with ldapDisplayName=OfficeLocations. 
> You won't find it.  Additionally, if you pull up any user in your AD with 
> ldp.exe or ADSI Edit, you won't see OfficeLocations in the returned 
> result.
>
> I can confirm with certainty that the actual AD attribute name is 
> physicalDeliveryOfficeName.  I just checked the MS source code to be sure.
>
> While it is possible to call the IADsUser property methods from .NET (link 
> here: ), you wouldn't want to do it this way because it forces you to bind 
> to the object.
>
> Regarding the question about arrays, attributes in AD can be single or 
> multivalued.  In order to implement a general API for handling both, they 
> are all treated as multi-valued in S.DS.
>
> Thus, the correct pattern for dealing with this in C# would go something 
> like:
>
> searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
> SearchResultCollection results;
> using (results = searcher.FindAll())
> {
> foreach(SearchResult result in results)
> {
> string office;
> if (result.Properties.Contains("physicalDeliveryOfficeName"))
>    office = (string) result.Properties["physicalDeliveryOfficeName"][0];
> }
> }
>
> HTH,
>
> Joe K.
>
>
> "Martin"  wrote in message 
> news:e7WMgVDTFHA.3308@TK2MSFTNGP14.phx.gbl...
>> Hi Joe,
>>
>> Thanks a lot for the reply.
>> I have taken your comments about code efficiency on board and will 
>> implement all of you suggestions.
>>
>> The code I am using is running on a windows 2003 server.
>> I have been assured by our network people that the "OfficeLocations" 
>> property does exist in the schema and they insist that they have not 
>> added this property to the schema.
>> The code below (VB script) does grab this property, so it can be obtained 
>> from vb script but I can't find how to get it from .net.
>>
>> However from what I can gather about this property, it is not returned as 
>> a single value, it is returnd as a "C struct" becuase there can be more 
>> that one office location assosiated with a user!!  so i guess it has to 
>> be assosited with some sort of array object..
>>
>> If  you could shed any more light on this for me then I would appreciate 
>> it.
>>
>> one interesting point is that the VB Script code below returns the users 
>> full name as  "FullName" where as my .net code returns the same property 
>> as "DisplayName" as maybe there is some discrepancy in naming.
>>
>>
>> cheers
>>
>> martin.
>>
>>
>>
>>
>> =================start code snippet==================================
>> Dim cont
>> Dim usr
>> Dim office
>> Dim searching, searchName, searchDept, searchOffice
>>
>> ' LDAP bind and open user OU
>>
>> Set cont = GetObject("LDAP://OU=mudomain users ,DC=mydomain,DC=local")
>>
>> ' Check for search criterium
>> If (Len(Request.QueryString("name")) > 0 Or 
>> Len(Request.QueryString("dept"))
>> > 0 Or Len(Request.QueryString("office")) > 0) Then
>> searching = true
>> Else
>> searching = false
>> End If
>> searchName = Request.QueryString("name")
>> searchDept = Request.QueryString("dept")
>> searchOffice = Request.QueryString("office")
>>
>> ' Enumerate through the users
>> row = 0
>> For Each obj In cont
>> Set usr = cont.GetObject("user", obj.Name)
>>
>> ' safely grab the office location - this throws an exception
>> ' if the field is not populated, so must be handled gracefully
>> office = ""
>> On Error Resume Next
>> office = usr.OfficeLocations 
>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>
>> If searching = false Or (InStr(1, usr.FullName, searchName, 1) > 0 And 
>> InStr(1, usr.Department, searchDept, 1) > 0 And InStr(1, office, 
>> searchOffice, 1) > 0) Then
>> %>
>>  <tr>
>>   <td class="row">
>>    <a href="detail.asp?user=<%=obj.Name%>"><%=usr.FullName%></a>
>>   </td>
>>   <td class="row">
>>    <%=usr.Department%> 
>>   </td>
>>   <td class="row">
>>    <%=office%> 
>>   </td>
>>   <td class="row">
>>    <%=usr.TelephoneNumber%> 
>>   </td>
>>  </tr>
>> <%
>> End If
>> Next
>> %>
>> =================End code snippet==================================
>>
>>
>>
>>
>>
>>
>>
>> "Joe Kaplan (MVP - ADSI)"  
>> wrote in message news:%23vA%237R7SFHA.3308@TK2MSFTNGP14.phx.gbl...
>>> officeLocations isn't in the schema, so that won't work.  I'm not sure 
>>> exactly what attribute you want, but perhaps it is 
>>> physicalDeliveryOfficeName?
>>>
>>> Two other things while we are looking at your code:
>>> - Add the attributes you want back from AD to the PropertiesToLoad and 
>>> get the values directly from the SearchResult instead of using the 
>>> DirectoryEntry.  It should speed up your code by as much as an order of 
>>> magnitude.
>>> - Make sure you enclose all of your IDisposable objects (DirectoryEntry, 
>>> DirectorySearcher, SearchResultCollection) in "using" blocks so they get 
>>> disposed.  You want to prevent possible memory leaks, especially in 
>>> long-runnng processes like web apps.
>>>
>>> Joe K.
>>>
>>> "Martin"  wrote in message 
>>> news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
>>>> Hi,
>>>>
>>>> I am attempting to retrive a list of users from Ad via asp.net and 
>>>> display them on a page.
>>>> All is going well and I am returning all my desired fields apart from 
>>>> one that is called "officeLocations"
>>>> The code I am using is below.
>>>> Can anybody please shed any light on how I retrieve this property.
>>>>
>>>> getstring is a method that simple checks if the object is null before 
>>>> attempting to convert it to a string.
>>>>
>>>> cheers
>>>>
>>>> martin.
>>>>
>>>> foreach(System.DirectoryServices.SearchResult resEnt in 
>>>> mySearcher.FindAll())
>>>>    {
>>>>
>>>>     counter++;
>>>>     try
>>>>     {
>>>>      System.DirectoryServices.DirectoryEntry 
>>>> de=resEnt.GetDirectoryEntry();
>>>>      DisplayName = 
>>>> getString(de.Properties["DisplayName"].Value).ToString();
>>>>      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
>>>>      //Title = getString(de.Properties["Title"].Value).ToString();
>>>>      UserName = 
>>>> getString(de.Properties["sAMAccountName"].Value).ToString();
>>>>      FirstName = 
>>>> getString(de.Properties["GivenName"].Value).ToString();
>>>>      LastName = getString(de.Properties["sn"].Value).ToString();
>>>>      //Initials = 
>>>> getString(de.Properties["Initials"].Value).ToString();
>>>>      Company = getString(de.Properties["Company"].Value).ToString();
>>>>      Department = 
>>>> getString(de.Properties["Department"].Value).ToString();
>>>>      TelephoneNumber = 
>>>> getString(de.Properties["TelephoneNumber"].Value).ToString();
>>>>      OfficeLocations = 
>>>> getString(de.Properties["OfficeLocations"].Value).ToString(); 
>>>> <<<<<<<<<<<<Can't get this.............
>>>>
>>>
>>>
>>
>>
>
>
date: Fri, 29 Apr 2005 11:57:19 +1200   author:   Martin

Re: officelocation property from asp.net   
Hi Martin,

Here was the link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/invoking_adsi_properties.asp?frame=true

It is a little messy, but it works.  There is an easier syntax in .NET 2.0. 
Sorry for forgetting that.  :)

The source code access is a special MS program that is not open to the 
public.  Maybe someday.  MS doesn't let me post source code, but I am 
allowed to do what I just did was to verify something and report back to 
you.  Maybe someday MS will expand this program to a wider audience. 
They've made a lot of progress in the last few years on opening up the 
source, but there is still a ways to go for sure.

Joe K.

"Martin"  wrote in message 
news:OxLwE4ETFHA.580@TK2MSFTNGP15.phx.gbl...
> Hi joe,
>
> many thanks again for the reply.
> I will propabally get a chance to try this over the weekend and I will let 
> you know how it goes.
>
> regarding your email,
> how did you manage to "check the MS source code to be sure"
> is this something that I can do and is this source code publically 
> availible????
>
> also you refer to a link
>
>> While it is possible to call the IADsUser property methods from .NET 
>> (link here: ), you wouldn't want to do it this way because it forces you 
>> to bind to the object.
>
> is it possible to let me know this link.
>
> again, many thanks for your help.
>
> cheers
>
> martin
>
>
>
>
> "Joe Kaplan (MVP - ADSI)"  wrote 
> in message news:etI8W6DTFHA.3280@TK2MSFTNGP09.phx.gbl...
>> There is a confusion in terms here.  OfficeLocations is an ADSI property 
>> on the IADsUser interface, but it isn't an actual attribute in AD.  You 
>> can verify this for yourself by pulling up ldp.exe and doing a search in 
>> the schema container for an object with ldapDisplayName=OfficeLocations. 
>> You won't find it.  Additionally, if you pull up any user in your AD with 
>> ldp.exe or ADSI Edit, you won't see OfficeLocations in the returned 
>> result.
>>
>> I can confirm with certainty that the actual AD attribute name is 
>> physicalDeliveryOfficeName.  I just checked the MS source code to be 
>> sure.
>>
>> While it is possible to call the IADsUser property methods from .NET 
>> (link here: ), you wouldn't want to do it this way because it forces you 
>> to bind to the object.
>>
>> Regarding the question about arrays, attributes in AD can be single or 
>> multivalued.  In order to implement a general API for handling both, they 
>> are all treated as multi-valued in S.DS.
>>
>> Thus, the correct pattern for dealing with this in C# would go something 
>> like:
>>
>> searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
>> SearchResultCollection results;
>> using (results = searcher.FindAll())
>> {
>> foreach(SearchResult result in results)
>> {
>> string office;
>> if (result.Properties.Contains("physicalDeliveryOfficeName"))
>>    office = (string) result.Properties["physicalDeliveryOfficeName"][0];
>> }
>> }
>>
>> HTH,
>>
>> Joe K.
>>
>>
>> "Martin"  wrote in message 
>> news:e7WMgVDTFHA.3308@TK2MSFTNGP14.phx.gbl...
>>> Hi Joe,
>>>
>>> Thanks a lot for the reply.
>>> I have taken your comments about code efficiency on board and will 
>>> implement all of you suggestions.
>>>
>>> The code I am using is running on a windows 2003 server.
>>> I have been assured by our network people that the "OfficeLocations" 
>>> property does exist in the schema and they insist that they have not 
>>> added this property to the schema.
>>> The code below (VB script) does grab this property, so it can be 
>>> obtained from vb script but I can't find how to get it from .net.
>>>
>>> However from what I can gather about this property, it is not returned 
>>> as a single value, it is returnd as a "C struct" becuase there can be 
>>> more that one office location assosiated with a user!!  so i guess it 
>>> has to be assosited with some sort of array object..
>>>
>>> If  you could shed any more light on this for me then I would appreciate 
>>> it.
>>>
>>> one interesting point is that the VB Script code below returns the users 
>>> full name as  "FullName" where as my .net code returns the same property 
>>> as "DisplayName" as maybe there is some discrepancy in naming.
>>>
>>>
>>> cheers
>>>
>>> martin.
>>>
>>>
>>>
>>>
>>> =================start code snippet==================================
>>> Dim cont
>>> Dim usr
>>> Dim office
>>> Dim searching, searchName, searchDept, searchOffice
>>>
>>> ' LDAP bind and open user OU
>>>
>>> Set cont = GetObject("LDAP://OU=mudomain users ,DC=mydomain,DC=local")
>>>
>>> ' Check for search criterium
>>> If (Len(Request.QueryString("name")) > 0 Or 
>>> Len(Request.QueryString("dept"))
>>> > 0 Or Len(Request.QueryString("office")) > 0) Then
>>> searching = true
>>> Else
>>> searching = false
>>> End If
>>> searchName = Request.QueryString("name")
>>> searchDept = Request.QueryString("dept")
>>> searchOffice = Request.QueryString("office")
>>>
>>> ' Enumerate through the users
>>> row = 0
>>> For Each obj In cont
>>> Set usr = cont.GetObject("user", obj.Name)
>>>
>>> ' safely grab the office location - this throws an exception
>>> ' if the field is not populated, so must be handled gracefully
>>> office = ""
>>> On Error Resume Next
>>> office = usr.OfficeLocations 
>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>
>>> If searching = false Or (InStr(1, usr.FullName, searchName, 1) > 0 And 
>>> InStr(1, usr.Department, searchDept, 1) > 0 And InStr(1, office, 
>>> searchOffice, 1) > 0) Then
>>> %>
>>>  <tr>
>>>   <td class="row">
>>>    <a href="detail.asp?user=<%=obj.Name%>"><%=usr.FullName%></a>
>>>   </td>
>>>   <td class="row">
>>>    <%=usr.Department%> 
>>>   </td>
>>>   <td class="row">
>>>    <%=office%> 
>>>   </td>
>>>   <td class="row">
>>>    <%=usr.TelephoneNumber%> 
>>>   </td>
>>>  </tr>
>>> <%
>>> End If
>>> Next
>>> %>
>>> =================End code snippet==================================
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> "Joe Kaplan (MVP - ADSI)"  
>>> wrote in message news:%23vA%237R7SFHA.3308@TK2MSFTNGP14.phx.gbl...
>>>> officeLocations isn't in the schema, so that won't work.  I'm not sure 
>>>> exactly what attribute you want, but perhaps it is 
>>>> physicalDeliveryOfficeName?
>>>>
>>>> Two other things while we are looking at your code:
>>>> - Add the attributes you want back from AD to the PropertiesToLoad and 
>>>> get the values directly from the SearchResult instead of using the 
>>>> DirectoryEntry.  It should speed up your code by as much as an order of 
>>>> magnitude.
>>>> - Make sure you enclose all of your IDisposable objects 
>>>> (DirectoryEntry, DirectorySearcher, SearchResultCollection) in "using" 
>>>> blocks so they get disposed.  You want to prevent possible memory 
>>>> leaks, especially in long-runnng processes like web apps.
>>>>
>>>> Joe K.
>>>>
>>>> "Martin"  wrote in message 
>>>> news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
>>>>> Hi,
>>>>>
>>>>> I am attempting to retrive a list of users from Ad via asp.net and 
>>>>> display them on a page.
>>>>> All is going well and I am returning all my desired fields apart from 
>>>>> one that is called "officeLocations"
>>>>> The code I am using is below.
>>>>> Can anybody please shed any light on how I retrieve this property.
>>>>>
>>>>> getstring is a method that simple checks if the object is null before 
>>>>> attempting to convert it to a string.
>>>>>
>>>>> cheers
>>>>>
>>>>> martin.
>>>>>
>>>>> foreach(System.DirectoryServices.SearchResult resEnt in 
>>>>> mySearcher.FindAll())
>>>>>    {
>>>>>
>>>>>     counter++;
>>>>>     try
>>>>>     {
>>>>>      System.DirectoryServices.DirectoryEntry 
>>>>> de=resEnt.GetDirectoryEntry();
>>>>>      DisplayName = 
>>>>> getString(de.Properties["DisplayName"].Value).ToString();
>>>>>      EmailAddress = getString(de.Properties["Mail"].Value).ToString();
>>>>>      //Title = getString(de.Properties["Title"].Value).ToString();
>>>>>      UserName = 
>>>>> getString(de.Properties["sAMAccountName"].Value).ToString();
>>>>>      FirstName = 
>>>>> getString(de.Properties["GivenName"].Value).ToString();
>>>>>      LastName = getString(de.Properties["sn"].Value).ToString();
>>>>>      //Initials = 
>>>>> getString(de.Properties["Initials"].Value).ToString();
>>>>>      Company = getString(de.Properties["Company"].Value).ToString();
>>>>>      Department = 
>>>>> getString(de.Properties["Department"].Value).ToString();
>>>>>      TelephoneNumber = 
>>>>> getString(de.Properties["TelephoneNumber"].Value).ToString();
>>>>>      OfficeLocations = 
>>>>> getString(de.Properties["OfficeLocations"].Value).ToString(); 
>>>>> <<<<<<<<<<<<Can't get this.............
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Thu, 28 Apr 2005 23:04:59 -0500   author:   Joe Kaplan \(MVP - ADSI\)

Re: officelocation property from asp.net   
Hi Joe,

just thougt I'd let you know that I have now maaged to grab the property 
that I wanted.

It was the "physicalDeliveryOfficeName"

and thanks for posting the link..

cheers

martin.


"Joe Kaplan (MVP - ADSI)"  wrote 
in message news:OcTPeCHTFHA.2756@tk2msftngp13.phx.gbl...
> Hi Martin,
>
> Here was the link:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/invoking_adsi_properties.asp?frame=true
>
> It is a little messy, but it works.  There is an easier syntax in .NET 
> 2.0. Sorry for forgetting that.  :)
>
> The source code access is a special MS program that is not open to the 
> public.  Maybe someday.  MS doesn't let me post source code, but I am 
> allowed to do what I just did was to verify something and report back to 
> you.  Maybe someday MS will expand this program to a wider audience. 
> They've made a lot of progress in the last few years on opening up the 
> source, but there is still a ways to go for sure.
>
> Joe K.
>
> "Martin"  wrote in message 
> news:OxLwE4ETFHA.580@TK2MSFTNGP15.phx.gbl...
>> Hi joe,
>>
>> many thanks again for the reply.
>> I will propabally get a chance to try this over the weekend and I will 
>> let you know how it goes.
>>
>> regarding your email,
>> how did you manage to "check the MS source code to be sure"
>> is this something that I can do and is this source code publically 
>> availible????
>>
>> also you refer to a link
>>
>>> While it is possible to call the IADsUser property methods from .NET 
>>> (link here: ), you wouldn't want to do it this way because it forces you 
>>> to bind to the object.
>>
>> is it possible to let me know this link.
>>
>> again, many thanks for your help.
>>
>> cheers
>>
>> martin
>>
>>
>>
>>
>> "Joe Kaplan (MVP - ADSI)"  
>> wrote in message news:etI8W6DTFHA.3280@TK2MSFTNGP09.phx.gbl...
>>> There is a confusion in terms here.  OfficeLocations is an ADSI property 
>>> on the IADsUser interface, but it isn't an actual attribute in AD.  You 
>>> can verify this for yourself by pulling up ldp.exe and doing a search in 
>>> the schema container for an object with ldapDisplayName=OfficeLocations. 
>>> You won't find it.  Additionally, if you pull up any user in your AD 
>>> with ldp.exe or ADSI Edit, you won't see OfficeLocations in the returned 
>>> result.
>>>
>>> I can confirm with certainty that the actual AD attribute name is 
>>> physicalDeliveryOfficeName.  I just checked the MS source code to be 
>>> sure.
>>>
>>> While it is possible to call the IADsUser property methods from .NET 
>>> (link here: ), you wouldn't want to do it this way because it forces you 
>>> to bind to the object.
>>>
>>> Regarding the question about arrays, attributes in AD can be single or 
>>> multivalued.  In order to implement a general API for handling both, 
>>> they are all treated as multi-valued in S.DS.
>>>
>>> Thus, the correct pattern for dealing with this in C# would go something 
>>> like:
>>>
>>> searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
>>> SearchResultCollection results;
>>> using (results = searcher.FindAll())
>>> {
>>> foreach(SearchResult result in results)
>>> {
>>> string office;
>>> if (result.Properties.Contains("physicalDeliveryOfficeName"))
>>>    office = (string) result.Properties["physicalDeliveryOfficeName"][0];
>>> }
>>> }
>>>
>>> HTH,
>>>
>>> Joe K.
>>>
>>>
>>> "Martin"  wrote in message 
>>> news:e7WMgVDTFHA.3308@TK2MSFTNGP14.phx.gbl...
>>>> Hi Joe,
>>>>
>>>> Thanks a lot for the reply.
>>>> I have taken your comments about code efficiency on board and will 
>>>> implement all of you suggestions.
>>>>
>>>> The code I am using is running on a windows 2003 server.
>>>> I have been assured by our network people that the "OfficeLocations" 
>>>> property does exist in the schema and they insist that they have not 
>>>> added this property to the schema.
>>>> The code below (VB script) does grab this property, so it can be 
>>>> obtained from vb script but I can't find how to get it from .net.
>>>>
>>>> However from what I can gather about this property, it is not returned 
>>>> as a single value, it is returnd as a "C struct" becuase there can be 
>>>> more that one office location assosiated with a user!!  so i guess it 
>>>> has to be assosited with some sort of array object..
>>>>
>>>> If  you could shed any more light on this for me then I would 
>>>> appreciate it.
>>>>
>>>> one interesting point is that the VB Script code below returns the 
>>>> users full name as  "FullName" where as my .net code returns the same 
>>>> property as "DisplayName" as maybe there is some discrepancy in naming.
>>>>
>>>>
>>>> cheers
>>>>
>>>> martin.
>>>>
>>>>
>>>>
>>>>
>>>> =================start code snippet==================================
>>>> Dim cont
>>>> Dim usr
>>>> Dim office
>>>> Dim searching, searchName, searchDept, searchOffice
>>>>
>>>> ' LDAP bind and open user OU
>>>>
>>>> Set cont = GetObject("LDAP://OU=mudomain users ,DC=mydomain,DC=local")
>>>>
>>>> ' Check for search criterium
>>>> If (Len(Request.QueryString("name")) > 0 Or 
>>>> Len(Request.QueryString("dept"))
>>>> > 0 Or Len(Request.QueryString("office")) > 0) Then
>>>> searching = true
>>>> Else
>>>> searching = false
>>>> End If
>>>> searchName = Request.QueryString("name")
>>>> searchDept = Request.QueryString("dept")
>>>> searchOffice = Request.QueryString("office")
>>>>
>>>> ' Enumerate through the users
>>>> row = 0
>>>> For Each obj In cont
>>>> Set usr = cont.GetObject("user", obj.Name)
>>>>
>>>> ' safely grab the office location - this throws an exception
>>>> ' if the field is not populated, so must be handled gracefully
>>>> office = ""
>>>> On Error Resume Next
>>>> office = usr.OfficeLocations 
>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>
>>>> If searching = false Or (InStr(1, usr.FullName, searchName, 1) > 0 And 
>>>> InStr(1, usr.Department, searchDept, 1) > 0 And InStr(1, office, 
>>>> searchOffice, 1) > 0) Then
>>>> %>
>>>>  <tr>
>>>>   <td class="row">
>>>>    <a href="detail.asp?user=<%=obj.Name%>"><%=usr.FullName%></a>
>>>>   </td>
>>>>   <td class="row">
>>>>    <%=usr.Department%> 
>>>>   </td>
>>>>   <td class="row">
>>>>    <%=office%> 
>>>>   </td>
>>>>   <td class="row">
>>>>    <%=usr.TelephoneNumber%> 
>>>>   </td>
>>>>  </tr>
>>>> <%
>>>> End If
>>>> Next
>>>> %>
>>>> =================End code snippet==================================
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> "Joe Kaplan (MVP - ADSI)"  
>>>> wrote in message news:%23vA%237R7SFHA.3308@TK2MSFTNGP14.phx.gbl...
>>>>> officeLocations isn't in the schema, so that won't work.  I'm not sure 
>>>>> exactly what attribute you want, but perhaps it is 
>>>>> physicalDeliveryOfficeName?
>>>>>
>>>>> Two other things while we are looking at your code:
>>>>> - Add the attributes you want back from AD to the PropertiesToLoad and 
>>>>> get the values directly from the SearchResult instead of using the 
>>>>> DirectoryEntry.  It should speed up your code by as much as an order 
>>>>> of magnitude.
>>>>> - Make sure you enclose all of your IDisposable objects 
>>>>> (DirectoryEntry, DirectorySearcher, SearchResultCollection) in "using" 
>>>>> blocks so they get disposed.  You want to prevent possible memory 
>>>>> leaks, especially in long-runnng processes like web apps.
>>>>>
>>>>> Joe K.
>>>>>
>>>>> "Martin"  wrote in message 
>>>>> news:OmtBwVvSFHA.3144@TK2MSFTNGP09.phx.gbl...
>>>>>> Hi,
>>>>>>
>>>>>> I am attempting to retrive a list of users from Ad via asp.net and 
>>>>>> display them on a page.
>>>>>> All is going well and I am returning all my desired fields apart from 
>>>>>> one that is called "officeLocations"
>>>>>> The code I am using is below.
>>>>>> Can anybody please shed any light on how I retrieve this property.
>>>>>>
>>>>>> getstring is a method that simple checks if the object is null before 
>>>>>> attempting to convert it to a string.
>>>>>>
>>>>>> cheers
>>>>>>
>>>>>> martin.
>>>>>>
>>>>>> foreach(System.DirectoryServices.SearchResult resEnt in 
>>>>>> mySearcher.FindAll())
>>>>>>    {
>>>>>>
>>>>>>     counter++;
>>>>>>     try
>>>>>>     {
>>>>>>      System.DirectoryServices.DirectoryEntry 
>>>>>> de=resEnt.GetDirectoryEntry();
>>>>>>      DisplayName = 
>>>>>> getString(de.Properties["DisplayName"].Value).ToString();
>>>>>>      EmailAddress = 
>>>>>> getString(de.Properties["Mail"].Value).ToString();
>>>>>>      //Title = getString(de.Properties["Title"].Value).ToString();
>>>>>>      UserName = 
>>>>>> getString(de.Properties["sAMAccountName"].Value).ToString();
>>>>>>      FirstName = 
>>>>>> getString(de.Properties["GivenName"].Value).ToString();
>>>>>>      LastName = getString(de.Properties["sn"].Value).ToString();
>>>>>>      //Initials = 
>>>>>> getString(de.Properties["Initials"].Value).ToString();
>>>>>>      Company = getString(de.Properties["Company"].Value).ToString();
>>>>>>      Department = 
>>>>>> getString(de.Properties["Department"].Value).ToString();
>>>>>>      TelephoneNumber = 
>>>>>> getString(de.Properties["TelephoneNumber"].Value).ToString();
>>>>>>      OfficeLocations = 
>>>>>> getString(de.Properties["OfficeLocations"].Value).ToString(); 
>>>>>> <<<<<<<<<<<<Can't get this.............
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
date: Mon, 2 May 2005 16:36:23 +1200   author:   Martin

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us