A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Type of object for AdvancedSearch



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 16th 06, 06:45 AM posted to microsoft.public.outlook.program_vba
Renjith
external usenet poster
 
Posts: 5
Default Type of object for AdvancedSearch

Hello
When I do advanced search using the AdvancedSearch method, I get the results
in the AdvancedSearch complete method. I am using C# to do this. But I have
problem here. I am not able to get the type of the item that was returned in
the result. For example it can be a MailItem or ContactItem. If I cast it to
a mail item it will result in an exception. How can I find the type of the
item before casting it?
The code is given below.
private void outLookApp_AdvancedSearchComplete(Search searchObj)
{
applicationObject.AdvancedSearchComplete -= new
ApplicationEvents_11_AdvancedSearchCompleteEventHa ndler (outLookApp_AdvancedSearchComplete);

string strZipFile = Path.GetTempFileName() + ".zip";
string[] strTempFiles = new string[searchObj.Results.Count];
for( int nCount = 0; nCount searchObj.Results.Count; nCount++)
{
MailItem item = (MailItem)searchObj.Results[nCount+1]; //This will throw
an exception if the item is not a MailItem
string strMailPath = Path.GetTempFileName() + ".msg";
item.SaveAs(strMailPath, OlSaveAsType.olMSG);
Helper.ZipFile(strMailPath,strZipFile);
strTempFiles[nCount] = strMailPath;
}
}
  #2  
Old May 16th 06, 01:07 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Type of object for AdvancedSearch

I'm not a C# programmer, but my understanding is that the right approach in C# is to this kind of statement witih the Is operator to test for each object class

if (Item is Ol.MailItem)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Renjith" wrote in message ...
Hello
When I do advanced search using the AdvancedSearch method, I get the results
in the AdvancedSearch complete method. I am using C# to do this. But I have
problem here. I am not able to get the type of the item that was returned in
the result. For example it can be a MailItem or ContactItem. If I cast it to
a mail item it will result in an exception. How can I find the type of the
item before casting it?
The code is given below.
private void outLookApp_AdvancedSearchComplete(Search searchObj)
{
applicationObject.AdvancedSearchComplete -= new
ApplicationEvents_11_AdvancedSearchCompleteEventHa ndler (outLookApp_AdvancedSearchComplete);

string strZipFile = Path.GetTempFileName() + ".zip";
string[] strTempFiles = new string[searchObj.Results.Count];
for( int nCount = 0; nCount searchObj.Results.Count; nCount++)
{
MailItem item = (MailItem)searchObj.Results[nCount+1]; //This will throw
an exception if the item is not a MailItem
string strMailPath = Path.GetTempFileName() + ".msg";
item.SaveAs(strMailPath, OlSaveAsType.olMSG);
Helper.ZipFile(strMailPath,strZipFile);
strTempFiles[nCount] = strMailPath;
}
}

  #3  
Old May 16th 06, 02:28 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Type of object for AdvancedSearch

Or a Try...Catch block where if one item type cast fails another can be
tried.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sue Mosher [MVP-Outlook]" wrote in message
...
I'm not a C# programmer, but my understanding is that the right approach in
C# is to this kind of statement witih the Is operator to test for each
object class

if (Item is Ol.MailItem)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Renjith" wrote in message
...
Hello
When I do advanced search using the AdvancedSearch method, I get the
results
in the AdvancedSearch complete method. I am using C# to do this. But I
have
problem here. I am not able to get the type of the item that was returned
in
the result. For example it can be a MailItem or ContactItem. If I cast it
to
a mail item it will result in an exception. How can I find the type of the
item before casting it?
The code is given below.
private void outLookApp_AdvancedSearchComplete(Search searchObj)
{
applicationObject.AdvancedSearchComplete -= new
ApplicationEvents_11_AdvancedSearchCompleteEventHa ndler
(outLookApp_AdvancedSearchComplete);

string strZipFile = Path.GetTempFileName() + ".zip";
string[] strTempFiles = new string[searchObj.Results.Count];
for( int nCount = 0; nCount searchObj.Results.Count; nCount++)
{
MailItem item = (MailItem)searchObj.Results[nCount+1]; //This will throw
an exception if the item is not a MailItem
string strMailPath = Path.GetTempFileName() + ".msg";
item.SaveAs(strMailPath, OlSaveAsType.olMSG);
Helper.ZipFile(strMailPath,strZipFile);
strTempFiles[nCount] = strMailPath;
}
}


  #4  
Old May 17th 06, 12:19 PM posted to microsoft.public.outlook.program_vba
Renjith
external usenet poster
 
Posts: 5
Default Type of object for AdvancedSearch

thankyou for the hint, actually I have now the try catch blocks for each
type, but the code becomes a bit lengthy with 16 such blocks

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

Or a Try...Catch block where if one item type cast fails another can be
tried.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sue Mosher [MVP-Outlook]" wrote in message
...
I'm not a C# programmer, but my understanding is that the right approach in
C# is to this kind of statement witih the Is operator to test for each
object class

if (Item is Ol.MailItem)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Renjith" wrote in message
...
Hello
When I do advanced search using the AdvancedSearch method, I get the
results
in the AdvancedSearch complete method. I am using C# to do this. But I
have
problem here. I am not able to get the type of the item that was returned
in
the result. For example it can be a MailItem or ContactItem. If I cast it
to
a mail item it will result in an exception. How can I find the type of the
item before casting it?
The code is given below.
private void outLookApp_AdvancedSearchComplete(Search searchObj)
{
applicationObject.AdvancedSearchComplete -= new
ApplicationEvents_11_AdvancedSearchCompleteEventHa ndler
(outLookApp_AdvancedSearchComplete);

string strZipFile = Path.GetTempFileName() + ".zip";
string[] strTempFiles = new string[searchObj.Results.Count];
for( int nCount = 0; nCount searchObj.Results.Count; nCount++)
{
MailItem item = (MailItem)searchObj.Results[nCount+1]; //This will throw
an exception if the item is not a MailItem
string strMailPath = Path.GetTempFileName() + ".msg";
item.SaveAs(strMailPath, OlSaveAsType.olMSG);
Helper.ZipFile(strMailPath,strZipFile);
strTempFiles[nCount] = strMailPath;
}
}



  #5  
Old May 17th 06, 02:13 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Type of object for AdvancedSearch

It probably could be cut down by casting to a an object of indeterminate
type and testing the .Class property of the object and then casting it to
the correct type, all within a try...catch to handle any errors.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Renjith" wrote in message
...
thankyou for the hint, actually I have now the try catch blocks for each
type, but the code becomes a bit lengthy with 16 such blocks


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Move object type Bob Smith Outlook and VBA 1 May 16th 06 07:08 AM
Scope Parameter for AdvancedSearch Renjith Outlook - General Queries 1 May 12th 06 04:58 PM
Scope Parameter for AdvancedSearch Renjith Outlook - Using Contacts 1 May 12th 06 02:42 PM
AdvancedSearch Method in Exchange Server environment Howard Outlook and VBA 5 April 26th 06 06:55 PM
AdvancedSearch Serg Flic Outlook and VBA 1 January 10th 06 03:17 PM


All times are GMT +1. The time now is 12:26 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-2025 Outlook Banter.
The comments are property of their posters.