Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook - Using Forms (http://www.outlookbanter.com/outlook-using-forms/)
-   -   Outlook Advanced Search Problems...returns with an Error: Argument (http://www.outlookbanter.com/outlook-using-forms/95491-outlook-advanced-search-problems-returns.html)

amatuercoder151 October 1st 09 12:33 AM

Outlook Advanced Search Problems...returns with an Error: Argument
 
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 A " & 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


Ken Slovak - [MVP - Outlook] October 1st 09 02:13 PM

Outlook Advanced Search Problems...returns with an Error: Argument
 
See if replacing any spaces with "%20" works.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"amatuercoder151" wrote in
message ...
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 A " &
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




All times are GMT +1. The time now is 07:58 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com