[RESOLVED] Search/Filter through Outlook.AddressEntries
here is my code for getting all the contacts in outlook. My current contact count is 28533. As for now Im using cache to store all the contacts but my boss requires me not to use cache.
Code:
Dim oApp As New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
Dim dt As New DataTable
dt.Columns.Add("id", 0.GetType)
dt.Columns.Add("name", String.Empty.GetType)
dt.Columns.Add("alias", String.Empty.GetType)
dt.Columns.Add("firstname", String.Empty.GetType)
dt.Columns.Add("lastname", String.Empty.GetType)
dt.Columns.Add("contact_no", String.Empty.GetType)
dt.Columns.Add("department", String.Empty.GetType)
dt.Columns.Add("email", String.Empty.GetType)
dt.PrimaryKey = New DataColumn() {dt.Columns("id")}
'oNS.Logon(sUserName, sPassword, False, True)
Dim als As Outlook.AddressLists = oNS.AddressLists
Dim aes As Outlook.AddressEntries = als("Global Address List").AddressEntries()
Dim iAECount As Integer = aes.Count
For i As Integer = 1 To iAECount
Dim ae As Outlook.AddressEntry = aes.Item(i)
If ae IsNot Nothing Then
Dim eu As Outlook.ExchangeUser = ae.GetExchangeUser
If eu IsNot Nothing Then
dt.Rows.Add(New Object() {i, ae.Name, eu.Alias, eu.FirstName, eu.LastName, eu.MobileTelephoneNumber, _
eu.Department, eu.PrimarySmtpAddress})
End If
End If
Next
Re: Search/Filter through Outlook.AddressEntries
Hello savior14,
I have read your post, but I don't seem to see any questions in there.
What exactly are you wanting help with?
Also, to be clear, are you creating a Web Application?
Gary
Re: Search/Filter through Outlook.AddressEntries
yes its a web application. (sorry for the late response)
as for now, in order to look for a single person, let's say john smith, im looping through a 25k+ records just to look for that record. quite a hassle.
as ive said, my boss also doesn't want me to use cache. is there any .search .filter function to only show a record who has a name 'john' and a surname 'smith' throughout the whole address list?
Re: Search/Filter through Outlook.AddressEntries
Hello,
In all honesty, I am not sure.
Although you are creating a Web Application, the specific question you are asking relates to a function within Microsoft Office, specifically Outlook.
As a result, I think this question will be best answered in the Office Development Forum where a lot of clever Office Development guys hang out :)
Gary
Re: Search/Filter through Outlook.AddressEntries
thanks for moving thread. :)
Re: Search/Filter through Outlook.AddressEntries
Have you tried using the .Restrict method of the Items collection?
Or how about the .Find or .Get methods of the Items collection?
Re: Search/Filter through Outlook.AddressEntries
Quote:
Originally Posted by
RobDog888
Have you tried using the .Restrict method of the Items collection?
Or how about the .Find or .Get methods of the Items collection?
not yet. I'll give it a try and will update you the result. :)
Re: Search/Filter through Outlook.AddressEntries
checked it but I found no restrict/find/get methods on either Outlook.AddressLists or Outlook.AddressEntries.
Re: Search/Filter through Outlook.AddressEntries
Not directly at the parent level but at the Items. Try - aes.Item
1 Attachment(s)
Re: Search/Filter through Outlook.AddressEntries
Quote:
Originally Posted by
RobDog888
Not directly at the parent level but at the Items. Try - aes.Item
no methods/properties found on typing aes.Item unless you specify the index like aes.Item(indexNo) and still no search methods found.
just in case you needed the sample project, please see the attached file. :)
Re: Search/Filter through Outlook.AddressEntries
Ok seems the Address Entries are a different collection.
To start, I optimized your code so it doesnt GetExchangeUser for every single entry as filtered by type
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim aes As Outlook.AddressEntries
Dim ae As Outlook.AddressEntry
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
aes = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries
For Each ae In aes
If ae.AddressEntryUserType = olExchangeAgentAddressEntry Or ae.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then
eu = ae.GetExchangeUser
If Not eu Is Nothing Then
Console.WriteLine(ae.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
End If
Next
eu = Nothing
ae = Nothing
aes = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
Re: Search/Filter through Outlook.AddressEntries
And here is how to directly get the exchange user without looping.
Replace USER NAME with your desired search name.
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("USER NAME").GetExchangeUser()
If Not eu Is Nothing Then
Console.WriteLine(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
eu = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
1 Attachment(s)
Re: Search/Filter through Outlook.AddressEntries
Wow, this is what Ive been searching for! It works like as if you're using the quick search of outlook.
Any way to search like the "Advance Find" of outlook? where you can specify what fields you only wanted to look? (see image attachment below)
Quote:
Originally Posted by
RobDog888
And here is how to directly get the exchange user without looping.
Replace USER NAME with your desired search name.
vb Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook.OlAddressEntryUserType
'Add reference to MS Outlook xx.x Object Library
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oApp As Outlook.Application
Dim eu As Outlook.ExchangeUser
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List").AddressEntries("USER NAME").GetExchangeUser()
If Not eu Is Nothing Then
Console.WriteLine(eu.Name + ": " + eu.Alias + ", " + eu.FirstName + ", " + eu.LastName + ", " + eu.MobileTelephoneNumber + ", " + eu.Department + ", " + eu.PrimarySmtpAddress)
End If
eu = Nothing
oApp.Quit()
oApp = Nothing
End Sub
End Class
Re: Search/Filter through Outlook.AddressEntries
You mean like searching for content in particular areas?
If so take a look at my Search Folder code - http://www.vbforums.com/showthread.php?t=323157
Re: Search/Filter through Outlook.AddressEntries
Quote:
Originally Posted by
RobDog888
does this work on contacts too?
what I mean in Advance find(outlook >> New E-mail >> To button: >> Advance Find) is something like you're searching in a datatable.
Code:
Dim oApp As New Outlook.Application
Dim eu As Outlook.ExchangeUser
eu = oApp.GetNamespace("MAPI").AddressLists("Global Address List")
.AddressEntries("first_name LIKE '%MyFirstName%' AND email = '
[email protected]' OR display_name = 'blahblah'")
.GetExchangeUser()
Re: Search/Filter through Outlook.AddressEntries
If you get the folderpath to whatever folder you want to search in then it should work.
sScope = "SCOPE ('shallow traversal of " & Chr$(34) & oFolder.Folder.Path & Chr$(34) & "')" ... etc
Re: Search/Filter through Outlook.AddressEntries
it seems complicated to me, I can't understand the code :p
I'll mark this thread as resolve then if I have spare time, I'll study that search folder thing youve said. Thanks a lot RobDog888. :)
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
Its not that bad ;)
Just look at the AdvancedSearch method (it actually is the part that calls the search). The arguments are what I had set up and just the sScope argument is a bit but the others are straight forward.
sFilter is the WHERE clause like in SQL.
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
I don't know if I needed to make a new topic, but here it goes.
vb.net Code:
Private Sub Try4()
On Error Resume Next
Dim oApp As New Outlook.Application
Dim oInbox As Outlook.MAPIFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim sFolderPath As String = oInbox.FolderPath
'Build a scope string
Dim sScope As String = "SCOPE ('shallow traversal of " & Chr(34) & sFolderPath & Chr(34) & "')"
'Build a filter string (WHERE clause without the WHERE)
Dim sFilter As String = Chr(34) & ("urn:schemas:mailheader:subject") & Chr(34) & " LIKE 'RE:%'"
'Create the Search object by calling AdvancedFind
Dim oSearch As Outlook.Search = oApp.AdvancedSearch(sScope, sFilter, False, "RE Search")
'Save the Search as a Search Folder
Dim oSearchFolder As Outlook.MAPIFolder = oSearch.Save("RE Search")
'MsgBox(oSearchFolder.Items.Count & " Items found!")
'oSearchFolder.Delete
End Sub
I only see my custom made contacts in this folder and not the Global Address List contacts in this code.
vb.net Code:
Dim oInbox As Outlook.MAPIFolder = oApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
And about this line, is there any documented guide for the parameters? I don't know if it is used like this for contacts.
vb.net Code:
urn:schemas:contact:detail:email
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
If you specify Contacts then its personal contacts only, not the GAL. If you want the GAL then you need to create a folder object instance referencing that instead.
As for searching in the contacts you would use hte format - "urn:content-classes:person" I believe.
See this link for all the schema breakdowns - http://msdn.microsoft.com/en-us/libr...EXCHG.65).aspx
Re: [RESOLVED] Search/Filter through Outlook.AddressEntries
Hello everyone,
I have a question - I need to do a similar thing, but on the basis of the email address (i.e. I have a list of email addresses of people from my company and I need to get their display names, job titles and location). I don't know how to retrieve objects on the basis of the email address. I tried modifying the above solutions, but the results are wrong when trying it this way.
Code:
set appOutlook = CreateObject("Outlook.Application")
set objNameSpace = appOutlook.GetNameSpace("MAPI")
set objAddressLists = objNameSpace.AddressLists("Global Address List")
set objAddressEntry = objAddressLists.AddressEntries("[email protected]").GetExchangeUser()
strFullName = objAddressEntry.Name
strJobTitle = objAddressEntry.JobTitle
strBusinessAddress = objAddressEntry.OfficeLocation
msgBox strFullName & strJobTitle & strBusinessAddress
I am using vbscript. How can I search for object from the Global Address List? From the personal contact list I managed to use
to filter, but I don't know how to implement this here.
Thanks in advance!
Regards
Bartosz