Is there a RefreshNow action for Search Folder?

M

Mark B

VSTO, C#, OL2007

I need to refresh a search folder on Outlook Open since the DASL criteria
has a %Today function which works OK on the day the item first appears in
the folder but doesn't work the following day when I open up Outlook.

I have just changed the folder's refresh rate to 5 minutes but this still
means the user may get the wrong results when they first open Outlook in the
morning -- unless they presumably wait 5 minutes.

I saw that the folder object has a Refresh rate property but could find a
Refresh method to call.
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure where you're changing the search folder refresh rate, but
there's no such method in the Outlook object model. In fact, using the OOM
there isn't much you can do other than delete the existing search folder and
create a new one on each Outlook startup. Other than setting a search folder
using the Search object and saving the search to create a search folder
there isn't much to work with for you. You can get the existing search
folder, delete it and create a new one.

The Redemption (www.dimastr.com/redemption) object model has an
RDOSearchFolder object where you can call Stop() and Start() methods that
effectively force a refresh, but not in the Outlook object model.
 
M

Mark B

Yes I see now. The Refresh rate method was created by another programmer
here. It simply deleted the folder and recreated it again.
 
M

Mark B

Now I recreate the folders on Startup.

I have noticed some weird behavior though. Sometimes the folder titles
appear italicized and the folder icon dimmed. Then when I click on one the
titles appear normal again and I can see the search results in the
particular folder. The issue though is that the folder title no longer has
the number of items in the title, e.g. "My Search [23]". It appears as "My
Search". I set this property after I create the folder:

public void ReCreateAll()
{
foreach (SearchFolder f in sFolders.Values)
f.Create();
}

public void Create()
{
try
{
Outlook.Application olApp;
Outlook.Search search;

//Deleting existing search-folder
Remove();

//Initialization
olApp = Globals.ThisAddIn.Application;
search = olApp.AdvancedSearch(this.scopeStr, this.filter,
true, this.tag);

Outlook.MAPIFolder myFolder = search.Save(this.FolderName);
this.EntryId = myFolder.EntryID;
myFolder.ShowItemCount =
Microsoft.Office.Interop.Outlook.OlShowItemCount.olShowTotalItemCount;
Globals.ThisAddIn.SaveSearchFoldersInfo();

}
catch (Exception e)
{
AppLogger.LogException(e);
}
}



public void Remove()
{
if (this.folderEntryId != null)
{

Outlook.Application olApp;
olApp = Globals.ThisAddIn.Application;

try
{
Outlook.MAPIFolder existingFolder =
olApp.GetNamespace("MAPI").GetFolderFromID(this.folderEntryId,
Type.Missing);

if (existingFolder != null)
existingFolder.Delete();

//Remove folder's entryID
this.folderEntryId = null;

//Save the changes
Globals.ThisAddIn.SaveSearchFoldersInfo();
}
catch (Exception)
{
}
}
}
 
K

Ken Slovak - [MVP - Outlook]

Italicized/dimmed means the search folder hasn't been accessed in xx days
and has gone inactive. Touching it will force a rescan, as when you click in
it. Bolded with a number in square brackets indicates the number of unread
items.

This is all basic search folder UI, nothing special and nothing due to code.
 
M

Mark B

Thanks.

After I had been using Outlook all day, opening and closing it about 5 times
during the day, all folders suddenly appeared italicized.

Then when I clicked on any of them, the following message was displayed:

"Cannot display the folder. Microsoft Office Outlook cannot access the
specified folder location. The operation cannot be performed because the
object has been deleted."

My startup code does delete all folders and recreates them but generally
there have been no issues. Do you know what might be causing the message?
Note after I just restarted Outlook now, the folders were non-italicized and
displayed the correct results. I wouldn't want a user to have to do that
everyday though.





Ken Slovak - said:
Italicized/dimmed means the search folder hasn't been accessed in xx days
and has gone inactive. Touching it will force a rescan, as when you click
in it. Bolded with a number in square brackets indicates the number of
unread items.

This is all basic search folder UI, nothing special and nothing due to
code.




Mark B said:
Now I recreate the folders on Startup.

I have noticed some weird behavior though. Sometimes the folder titles
appear italicized and the folder icon dimmed. Then when I click on one
the titles appear normal again and I can see the search results in the
particular folder. The issue though is that the folder title no longer
has the number of items in the title, e.g. "My Search [23]". It appears
as "My Search". I set this property after I create the folder:

public void ReCreateAll()
{
foreach (SearchFolder f in sFolders.Values)
f.Create();
}

public void Create()
{
try
{
Outlook.Application olApp;
Outlook.Search search;

//Deleting existing search-folder
Remove();

//Initialization
olApp = Globals.ThisAddIn.Application;
search = olApp.AdvancedSearch(this.scopeStr, this.filter,
true, this.tag);

Outlook.MAPIFolder myFolder =
search.Save(this.FolderName);
this.EntryId = myFolder.EntryID;
myFolder.ShowItemCount =
Microsoft.Office.Interop.Outlook.OlShowItemCount.olShowTotalItemCount;
Globals.ThisAddIn.SaveSearchFoldersInfo();

}
catch (Exception e)
{
AppLogger.LogException(e);
}
}



public void Remove()
{
if (this.folderEntryId != null)
{

Outlook.Application olApp;
olApp = Globals.ThisAddIn.Application;

try
{
Outlook.MAPIFolder existingFolder =
olApp.GetNamespace("MAPI").GetFolderFromID(this.folderEntryId,
Type.Missing);

if (existingFolder != null)
existingFolder.Delete();

//Remove folder's entryID
this.folderEntryId = null;

//Save the changes
Globals.ThisAddIn.SaveSearchFoldersInfo();
}
catch (Exception)
{
}
}
}
 
K

Ken Slovak - [MVP - Outlook]

The cause of the message is pretty obvious from the message itself, no?
 
M

Mark B

I would think not because if the folder was deleted why would it still
appear in the list of folders (albeit italicized)? The message appears to
the right where list of search results normally appears.
 
K

Ken Slovak - [MVP - Outlook]

Was it actually deleted? Did you get the long-term EntryID (from MAPI) or
the EntryID from Outlook and save it to get the folder again? If it was
actually deleted then the folder list was corrupted.

Start Outlook using the /resetnavpane startup switch, which will reset the
navigation pane to the default if you suspect corruption in the view.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top