Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2007

Tip: Looking for answers? Try searching our database.

visual c# advancedsearch does not return results or will not fire

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
matt - 27 Jul 2007 14:52 GMT
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/topic56
189.aspx

http://showmeself.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&p
artqs=amonth%3d5%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_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)

{

}

}

}
Sue Mosher [MVP-Outlook] - 27 Jul 2007 16:29 GMT
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.

Signature

Sue Mosher, Outlook MVP
  Author of Microsoft Outlook 2007 Programming:
    Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54

> Please advise where this maybe best directed, since I really don't know vba
> well enough to help assist with learning C#.
[quoted text clipped - 201 lines]
>
> }
matt - 28 Jul 2007 02:50 GMT
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?

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.

Signature

Sue Mosher, Outlook MVP
  Author of Microsoft Outlook 2007 Programming:
    Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54

> Please advise where this maybe best directed, since I really don't know
> vba
[quoted text clipped - 204 lines]
>
> }
matt - 28 Jul 2007 05:39 GMT
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.

> Yeah, that did the trick, great to know what I was overlooking there.
> Definitely, thanks for pin-pointing that.
[quoted text clipped - 233 lines]
>>
>> }
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.