R
Renjith
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_AdvancedSearchCompleteEventHandler (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;
}
}
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_AdvancedSearchCompleteEventHandler (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;
}
}