A
amatuercoder151
Hi All,
I am facing a problem with using the advanced search function provided in
the outlook object model.
What i am trying to achieve is simple. I just want to open a pst, and able
to run a search on all the items( calender, mail, appointment...everything),
and then just get the all items count...thats all..
The code i have written is as follows:
Dim app As New Application
Dim pstinfo As [NameSpace]
pstinfo = app.GetNamespace("MAPI")
Dim objfolder As MAPIFolder = Nothing
app.Session.Logon("outlook", "", False, True)
Dim allfolders As Microsoft.Office.Interop.Outlook.Folders =
pstinfo.Folders
Dim i As Integer = 0
Dim ii As Integer = 0
Dim foldernames(10) As String
For Each folder In allfolders
Dim objtempfolder As MAPIFolder = folder
foldernames(i) = objtempfolder.Name
i = i + 1
Next
pstinfo.Session.AddStore(PST NAME HERE)
Dim matchfound As Integer = 0
For Each folder In pstinfo.Folders
matchfound = 0
Dim objtempfolder1 As MAPIFolder = folder
For i = 0 To 10
If objtempfolder1.Name = foldernames(i) Then
matchfound = 1
Exit For
End If
Next
If matchfound = 0 Then
objfolder = objtempfolder1
End If
Next
Dim scope As String = Nothing
scope = "'" & objfolder.folderpath & "'"
Dim search As Search = app.Session.Application.AdvancedSearch(scope,
, True, "")
pstinfo.Session.RemoveStore(objfolder)
app = Nothing
pstinfo = Nothing
objfolder = Nothing
search = Nothing
System.GC.Collect()
Private Sub app_AdvancedSearchComplete(ByVal SearchObject As
Microsoft.Office.Interop.Outlook.Search) Handles app.AdvancedSearchComplete
Dim results As Results
results = SearchObject.Results()
MsgBox("The Total Number of found in the PST Are: " & results.Count)
End Sub
This code works totally fine with almost all the PST's, until i encountered
a PST which had a mailbox named " Archived Folders". Thereby the
objfolder.folderpath variable comes out to be "\\ Archived Folders", and the
advanced search line throws an error saying Error: Argument Exception was
Unhandled:Could not complete the operation. One or more parameter values are
not valid.
For all others its working. Also one thing to mention is that "\\ Archived
Folders" has a starting space character, which i feel might be the problem.
Please if somebody could help me out, as i have tried all things, but
nothing works
I am facing a problem with using the advanced search function provided in
the outlook object model.
What i am trying to achieve is simple. I just want to open a pst, and able
to run a search on all the items( calender, mail, appointment...everything),
and then just get the all items count...thats all..
The code i have written is as follows:
Dim app As New Application
Dim pstinfo As [NameSpace]
pstinfo = app.GetNamespace("MAPI")
Dim objfolder As MAPIFolder = Nothing
app.Session.Logon("outlook", "", False, True)
Dim allfolders As Microsoft.Office.Interop.Outlook.Folders =
pstinfo.Folders
Dim i As Integer = 0
Dim ii As Integer = 0
Dim foldernames(10) As String
For Each folder In allfolders
Dim objtempfolder As MAPIFolder = folder
foldernames(i) = objtempfolder.Name
i = i + 1
Next
pstinfo.Session.AddStore(PST NAME HERE)
Dim matchfound As Integer = 0
For Each folder In pstinfo.Folders
matchfound = 0
Dim objtempfolder1 As MAPIFolder = folder
For i = 0 To 10
If objtempfolder1.Name = foldernames(i) Then
matchfound = 1
Exit For
End If
Next
If matchfound = 0 Then
objfolder = objtempfolder1
End If
Next
Dim scope As String = Nothing
scope = "'" & objfolder.folderpath & "'"
Dim search As Search = app.Session.Application.AdvancedSearch(scope,
, True, "")
pstinfo.Session.RemoveStore(objfolder)
app = Nothing
pstinfo = Nothing
objfolder = Nothing
search = Nothing
System.GC.Collect()
Private Sub app_AdvancedSearchComplete(ByVal SearchObject As
Microsoft.Office.Interop.Outlook.Search) Handles app.AdvancedSearchComplete
Dim results As Results
results = SearchObject.Results()
MsgBox("The Total Number of found in the PST Are: " & results.Count)
End Sub
This code works totally fine with almost all the PST's, until i encountered
a PST which had a mailbox named " Archived Folders". Thereby the
objfolder.folderpath variable comes out to be "\\ Archived Folders", and the
advanced search line throws an error saying Error: Argument Exception was
Unhandled:Could not complete the operation. One or more parameter values are
not valid.
For all others its working. Also one thing to mention is that "\\ Archived
Folders" has a starting space character, which i feel might be the problem.
Please if somebody could help me out, as i have tried all things, but
nothing works