PC Review


Reply
Thread Tools Rate Thread

AdvancedSearchComplete Search param not immediately ready for use

 
 
sb
Guest
Posts: n/a
 
      23rd Jul 2009
Hello,

I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and
Outlook 2003. I have a bit of functionality that executes an advancedsearch
and catches the AdvancedSearchComplete event. However, when the results come
back, the Search parameter passed to the event handler does not appear to be
ready for use.

The search:

sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject
string%' AND ";
sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE '%text
description%'";

//Execute the search
try
{
Outlook.Application a = m_addIn.Application;

sScope = "'\\\\valid folder\\'";
a.AdvancedSearch(sScope, sFilter, true, "Tag");
}


The event handler:

private void m_outlook_AdvancedSearchComplete(Outlook.Search
searchObj)
{
//MessageBox.Show(searchObj.Results.Count.ToString());


for (int i = 1; i <= searchObj.Results.Count; i++)
{
//do stuff
}


Everything seems to be working fine, the search is successful and the
AdvancedSearchComplete event fires when it is done. However, when
AdvancedSearchComplete is fired as expected, searchObj.Results.Count is
ALWAYS zero. But... If that MessageBox.Show line is uncommented, it always
displays '0', but then the subsequent calls to searchObj in the for... and
beyond correctly reflect the search Results. I have tried a Thread.Sleep()
call in there to no avail.

Thoughts? I thought the results were guaranteed to be ready when this event
fires. Is there some setting I am missing somewhere?

thanks
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Jul 2009
I can't repro that here using VS 2008, C# and Outlook 2003. I used this
search as a test:

Outlook.Search search = _outlook.AdvancedSearch("Inbox",
"urn:schemas:mailheader:subject = 'Checking in'", true, "Foo");

When the event fired the MessageBox showed 1 result in my Inbox, as
expected.

If you want to loop the Results collection you will need to use
GetFirst()/GetLast() or get an IEnumerator object to iterate the collection
that way.

--
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


"sb" <(E-Mail Removed)> wrote in message
news:AD2A8C67-09BE-41FA-9014-(E-Mail Removed)...
> Hello,
>
> I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and
> Outlook 2003. I have a bit of functionality that executes an
> advancedsearch
> and catches the AdvancedSearchComplete event. However, when the results
> come
> back, the Search parameter passed to the event handler does not appear to
> be
> ready for use.
>
> The search:
>
> sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject
> string%' AND ";
> sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE
> '%text
> description%'";
>
> //Execute the search
> try
> {
> Outlook.Application a = m_addIn.Application;
>
> sScope = "'\\\\valid folder\\'";
> a.AdvancedSearch(sScope, sFilter, true, "Tag");
> }
>
>
> The event handler:
>
> private void m_outlook_AdvancedSearchComplete(Outlook.Search
> searchObj)
> {
> //MessageBox.Show(searchObj.Results.Count.ToString());
>
>
> for (int i = 1; i <= searchObj.Results.Count; i++)
> {
> //do stuff
> }
>
>
> Everything seems to be working fine, the search is successful and the
> AdvancedSearchComplete event fires when it is done. However, when
> AdvancedSearchComplete is fired as expected, searchObj.Results.Count is
> ALWAYS zero. But... If that MessageBox.Show line is uncommented, it
> always
> displays '0', but then the subsequent calls to searchObj in the for... and
> beyond correctly reflect the search Results. I have tried a
> Thread.Sleep()
> call in there to no avail.
>
> Thoughts? I thought the results were guaranteed to be ready when this
> event
> fires. Is there some setting I am missing somewhere?
>
> thanks


 
Reply With Quote
 
sb
Guest
Posts: n/a
 
      23rd Jul 2009
Thank you for your response, Ken.

It seems strange it only happens for me. Are you using .Net 2.0 (as opposed
to the VS2008 default of 3.5)? Also, I am running on Win 7 RC, and the email
accounts in my test config of Outlook are just a couple of hotmail addresses
using Outlook Connector. Not sure why any of these would make any difference.

In any event, I finally just solved this problem with an
Application.DoEvents() call in the event handler. Weird.

Forgive me, I am no Outlook extensibility master. While
GetFirst()/GetNext() may be better in some way, why would a for() loop not
work to iterate the results?

thanks



"Ken Slovak - [MVP - Outlook]" wrote:

> I can't repro that here using VS 2008, C# and Outlook 2003. I used this
> search as a test:
>
> Outlook.Search search = _outlook.AdvancedSearch("Inbox",
> "urn:schemas:mailheader:subject = 'Checking in'", true, "Foo");
>
> When the event fired the MessageBox showed 1 result in my Inbox, as
> expected.
>
> If you want to loop the Results collection you will need to use
> GetFirst()/GetLast() or get an IEnumerator object to iterate the collection
> that way.
>
> --
> 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
>
>
> "sb" <(E-Mail Removed)> wrote in message
> news:AD2A8C67-09BE-41FA-9014-(E-Mail Removed)...
> > Hello,
> >
> > I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and
> > Outlook 2003. I have a bit of functionality that executes an
> > advancedsearch
> > and catches the AdvancedSearchComplete event. However, when the results
> > come
> > back, the Search parameter passed to the event handler does not appear to
> > be
> > ready for use.
> >
> > The search:
> >
> > sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject
> > string%' AND ";
> > sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE
> > '%text
> > description%'";
> >
> > //Execute the search
> > try
> > {
> > Outlook.Application a = m_addIn.Application;
> >
> > sScope = "'\\\\valid folder\\'";
> > a.AdvancedSearch(sScope, sFilter, true, "Tag");
> > }
> >
> >
> > The event handler:
> >
> > private void m_outlook_AdvancedSearchComplete(Outlook.Search
> > searchObj)
> > {
> > //MessageBox.Show(searchObj.Results.Count.ToString());
> >
> >
> > for (int i = 1; i <= searchObj.Results.Count; i++)
> > {
> > //do stuff
> > }
> >
> >
> > Everything seems to be working fine, the search is successful and the
> > AdvancedSearchComplete event fires when it is done. However, when
> > AdvancedSearchComplete is fired as expected, searchObj.Results.Count is
> > ALWAYS zero. But... If that MessageBox.Show line is uncommented, it
> > always
> > displays '0', but then the subsequent calls to searchObj in the for... and
> > beyond correctly reflect the search Results. I have tried a
> > Thread.Sleep()
> > call in there to no avail.
> >
> > Thoughts? I thought the results were guaranteed to be ready when this
> > event
> > fires. Is there some setting I am missing somewhere?
> >
> > thanks

>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      23rd Jul 2009
I did the test in an addin I'm working on which happens to use Framework 2.0
and not 3.5. The code was tested on WinXP SP3 and Outlook 2003 SP3.

I'd guess that the connector and hotmail wouldn't make a difference, the
search is being done on a specific folder or folders. I don't use the
connector, are the folders you were searching local in a PST file? If so
then there shouldn't be a difference. I happened to test using a cached
Exchange mailbox.

I wonder if using Application.AdvancedSearch() as a function, as I did might
make a difference. You might try that and see.

I suggested using the Get* functions rather than something like
searchObject[i] just because you don't have to deal with Outlook collections
starting with Item[1] and not Item[0]. One less thing to remember. Not a big
deal, I often use a for loop like yours.

--
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


"sb" <(E-Mail Removed)> wrote in message
news:170CA22D-495B-4399-ADE6-(E-Mail Removed)...
> Thank you for your response, Ken.
>
> It seems strange it only happens for me. Are you using .Net 2.0 (as
> opposed
> to the VS2008 default of 3.5)? Also, I am running on Win 7 RC, and the
> email
> accounts in my test config of Outlook are just a couple of hotmail
> addresses
> using Outlook Connector. Not sure why any of these would make any
> difference.
>
> In any event, I finally just solved this problem with an
> Application.DoEvents() call in the event handler. Weird.
>
> Forgive me, I am no Outlook extensibility master. While
> GetFirst()/GetNext() may be better in some way, why would a for() loop not
> work to iterate the results?
>
> thanks


 
Reply With Quote
 
sb
Guest
Posts: n/a
 
      24th Jul 2009


"Ken Slovak - [MVP - Outlook]" wrote:

>
> I suggested using the Get* functions rather than something like
> searchObject[i] just because you don't have to deal with Outlook collections
> starting with Item[1] and not Item[0]. One less thing to remember. Not a big
> deal, I often use a for loop like yours.
>


Ah yes - I already encountered and passed that annoyance. <g>

Thanks again for your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP Search immediately says No Results Wayne Windows XP General 7 4th May 2008 04:45 PM
search for any lowercase immediately followed by an UPPERCASE HotelLending@gmail.com Microsoft Excel Worksheet Functions 9 4th Nov 2007 01:04 AM
Directory.GetFiles search param John Smith Microsoft C# .NET 2 5th Feb 2005 07:07 AM
Search window open ready to type ben Windows XP Help 2 1st Feb 2004 06:18 PM
Using search engine immediately closes IE James Windows XP Internet Explorer 1 30th Jul 2003 04:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 AM.