M
matt
Please advise where this maybe best directed, since I really don't know vba
well enough to help assist with learning C#.
Also first time w/ Outlook com object.
these are the only examples using advancedsearch w/ C# I have found online:
http://www.devnewsgroups.net/group/microsoft.public.exchange.development/topic56189.aspx
http://showmeself.spaces.live.com/?...ogview&_c=BlogPart&partqs=amonth=5&ayear=2007
I have tried this a few ways, but here is code as I have it now.
Would prefer to be able to pass the path as referenced below - which I was
able to do it seems - but changed method and changed path back to "inbox"
to be sure that wasn't the issue.
Please help, goal is to get item (mail) count using advanced find to search
subfolders.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
namespace outlook_TLE_Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
// ThisAdvancedSearchComplete();
// findItems();
Test3();
}
public void Test3()
{
_ThisAdvancedSearchComplete();
}
private Outlook.Folders GetFolders()
{
throw new Exception("The method or operation is not implemented.");
}
// Below Start test 3 here
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// void _ThisAdvancedSearchComplete(object sender, EventArgs e)
public void _ThisAdvancedSearchComplete()
{
Outlook.Application olapp_1 = new Outlook.Application();
Outlook.NameSpace ns = olapp_1.GetNamespace("MAPI");
ns.Logon(Missing.Value,Missing.Value,false,true);
Outlook.MAPIFolder TL_Folder = ns.Application.Session.Folders[2];
int count = TL_Folder.Items.Count;
// set up search parameters
// string path = ns.Application.Session.Folders[2].FolderPath;
string path = TL_Folder.FolderPath;
// string Scope = "'" + path + "'";
string Scope = @"Inbox";
// string filter = "urn:schemas:mailheader:subject = '%a%'";
string filter = @"""subject"" LIKE '%a%'";
//string filter = @"urn:schemas:httpmail:msgfolderroot:kind = '%'";
object subfolders = true;
string tag = "SearchForMail";
// const string tag = @"SearchForMail";
try
{
olapp_1.AdvancedSearchComplete += new
Outlook.ApplicationEvents_11_AdvancedSearchCompleteEventHandler(olapp_1_AdvancedSearchComplete);
//Outlook.Search SearchObject = olapp_1.AdvancedSearch(Scope, filter,
subfolders, tag);
label2.Text = path.ToString();
startAdvancedSearch(olapp_1);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show(ex.Message + " " + "\\n" + ex.StackTrace);
}
}
void olapp_1_AdvancedSearchComplete(Outlook.Search SearchObject)
{
if (SearchObject != null)
{
MessageBox.Show(SearchObject.Results.Count.ToString());
}
//throw new Exception("The method or operation is not implemented.");
}
private static void startAdvancedSearch(Outlook._Application olapp_1)
{
// string Scope = "'" + path + "'";
string Scope = @"Inbox";
// string filter = "urn:schemas:mailheader:subject = '%a%'";
string filter = @"""subject"" LIKE '%a%'";
//string filter = @"urn:schemas:httpmail:msgfolderroot:kind = '%'";
object subfolders = true;
string tag = "SearchForMail";
// const string tag = @"SearchForMail";
Outlook.Search SearchObject = olapp_1.AdvancedSearch(Scope, filter,
subfolders, tag);
}
// End test 3
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
well enough to help assist with learning C#.
Also first time w/ Outlook com object.
these are the only examples using advancedsearch w/ C# I have found online:
http://www.devnewsgroups.net/group/microsoft.public.exchange.development/topic56189.aspx
http://showmeself.spaces.live.com/?...ogview&_c=BlogPart&partqs=amonth=5&ayear=2007
I have tried this a few ways, but here is code as I have it now.
Would prefer to be able to pass the path as referenced below - which I was
able to do it seems - but changed method and changed path back to "inbox"
to be sure that wasn't the issue.
Please help, goal is to get item (mail) count using advanced find to search
subfolders.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using System.Runtime.InteropServices;
namespace outlook_TLE_Reader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
// ThisAdvancedSearchComplete();
// findItems();
Test3();
}
public void Test3()
{
_ThisAdvancedSearchComplete();
}
private Outlook.Folders GetFolders()
{
throw new Exception("The method or operation is not implemented.");
}
// Below Start test 3 here
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// void _ThisAdvancedSearchComplete(object sender, EventArgs e)
public void _ThisAdvancedSearchComplete()
{
Outlook.Application olapp_1 = new Outlook.Application();
Outlook.NameSpace ns = olapp_1.GetNamespace("MAPI");
ns.Logon(Missing.Value,Missing.Value,false,true);
Outlook.MAPIFolder TL_Folder = ns.Application.Session.Folders[2];
int count = TL_Folder.Items.Count;
// set up search parameters
// string path = ns.Application.Session.Folders[2].FolderPath;
string path = TL_Folder.FolderPath;
// string Scope = "'" + path + "'";
string Scope = @"Inbox";
// string filter = "urn:schemas:mailheader:subject = '%a%'";
string filter = @"""subject"" LIKE '%a%'";
//string filter = @"urn:schemas:httpmail:msgfolderroot:kind = '%'";
object subfolders = true;
string tag = "SearchForMail";
// const string tag = @"SearchForMail";
try
{
olapp_1.AdvancedSearchComplete += new
Outlook.ApplicationEvents_11_AdvancedSearchCompleteEventHandler(olapp_1_AdvancedSearchComplete);
//Outlook.Search SearchObject = olapp_1.AdvancedSearch(Scope, filter,
subfolders, tag);
label2.Text = path.ToString();
startAdvancedSearch(olapp_1);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show(ex.Message + " " + "\\n" + ex.StackTrace);
}
}
void olapp_1_AdvancedSearchComplete(Outlook.Search SearchObject)
{
if (SearchObject != null)
{
MessageBox.Show(SearchObject.Results.Count.ToString());
}
//throw new Exception("The method or operation is not implemented.");
}
private static void startAdvancedSearch(Outlook._Application olapp_1)
{
// string Scope = "'" + path + "'";
string Scope = @"Inbox";
// string filter = "urn:schemas:mailheader:subject = '%a%'";
string filter = @"""subject"" LIKE '%a%'";
//string filter = @"urn:schemas:httpmail:msgfolderroot:kind = '%'";
object subfolders = true;
string tag = "SearchForMail";
// const string tag = @"SearchForMail";
Outlook.Search SearchObject = olapp_1.AdvancedSearch(Scope, filter,
subfolders, tag);
}
// End test 3
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}