![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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/m...opic56189.aspx http://showmeself.spaces.live.com/?_...26ayear%3d2007 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_AdvancedSearchComplet eEventHandler(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.ToStrin g()); } //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) { } } } |
Ads |
#2
|
|||
|
|||
![]()
The main problem is probably with your search string. I don't write C#, so you'll have to build the string yourself, but the final result to search for the letter "a" in the subject would be:
"urn:schemas:mailheader:subject" Like '%a%' Note that the property name needs quotation marks around it. The easiest way to see the correct syntax, BTW, is to filter a view and then look at the view's SQL tab. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "matt" wrote in message ... 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/m...opic56189.aspx http://showmeself.spaces.live.com/?_...26ayear%3d2007 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_AdvancedSearchComplet eEventHandler(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.ToStrin g()); } //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) { } } } |
#3
|
|||
|
|||
![]()
Yeah, that did the trick, great to know what I was overlooking there.
Definitely, thanks for pin-pointing that. Now I need to return all items, regarless of subject or mail type - calendar item even. It may be an emtpy subject field will get me that - but in outlook you must specify any outlook item when doing an advanced search through the gui. But if it works, I still don't know what to pass - wild card - to catch everything. Even still, probably another approach needed to return what I want anyway. You know of a webdav clause that would return all items? "Sue Mosher [MVP-Outlook]" wrote in message ... The main problem is probably with your search string. I don't write C#, so you'll have to build the string yourself, but the final result to search for the letter "a" in the subject would be: "urn:schemas:mailheader:subject" Like '%a%' Note that the property name needs quotation marks around it. The easiest way to see the correct syntax, BTW, is to filter a view and then look at the view's SQL tab. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "matt" wrote in message ... 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/m...opic56189.aspx http://showmeself.spaces.live.com/?_...26ayear%3d2007 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_AdvancedSearchComplet eEventHandler(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.ToStrin g()); } //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) { } } } |
#4
|
|||
|
|||
![]()
nevermind, this is all I needed
string filter = @""; Also, imediately below, that was a really cool tip, since I never even thought to do that before. The easiest way to see the correct syntax, BTW, is to filter a view and then look at the view's SQL tab. "matt" wrote in message ... Yeah, that did the trick, great to know what I was overlooking there. Definitely, thanks for pin-pointing that. Now I need to return all items, regarless of subject or mail type - calendar item even. It may be an emtpy subject field will get me that - but in outlook you must specify any outlook item when doing an advanced search through the gui. But if it works, I still don't know what to pass - wild card - to catch everything. Even still, probably another approach needed to return what I want anyway. You know of a webdav clause that would return all items? "Sue Mosher [MVP-Outlook]" wrote in message ... The main problem is probably with your search string. I don't write C#, so you'll have to build the string yourself, but the final result to search for the letter "a" in the subject would be: "urn:schemas:mailheader:subject" Like '%a%' Note that the property name needs quotation marks around it. The easiest way to see the correct syntax, BTW, is to filter a view and then look at the view's SQL tab. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "matt" wrote in message ... 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/m...opic56189.aspx http://showmeself.spaces.live.com/?_...26ayear%3d2007 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_AdvancedSearchComplet eEventHandler(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.ToStrin g()); } //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) { } } } |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Application_ItemSend Doesn't Fire | dch3 | Outlook and VBA | 2 | May 19th 07 09:48 PM |
FIRE WALL??? | ECHO FREEMAN | Outlook Express | 3 | April 13th 07 03:42 AM |
Rules Don't Automatically Fire | dln | Outlook - General Queries | 0 | January 2nd 07 10:01 PM |
Search results in Advanced Find does not return correct contacts | Jeremiah Traxler | Outlook - Using Contacts | 0 | June 26th 06 11:52 PM |
Outlook events will not fire | Alex | Outlook and VBA | 2 | April 28th 06 05:12 PM |