R
Ryan Taylor
Hello,
I am using Outlook 2007 and am attempting to create and later reference a
folder above the Inbox folder. It turns out, that this code works perfectly
when the "Use Cached Exchange Mode" option is unchecked. When it is checked,
the code acts differently in two ways: 1, when looping through the folders,
my custom folder is not found (even though it exists), 2, since the folder is
not found, it attempts to create it, this create attempt fails with an
exception.
The exception is "System.Runtime.InteropServices.COMException (0x80020009):
Cannot create the folder.
at Microsoft.Office.Interop.Outlook.FoldersClass.Add(String Name, Object
Type)"
The code I use is below, basically all the code does is loop through the
list of folders directly above the inbox folder and if it finds our folder it
returns it, if our folder isn't found, then it is created and returned:
====================================================
private MAPIFolder GetCustomFolder()
{
MAPIFolder customFolder = null;
NameSpace ns = _app.Session;
MAPIFolder mapiFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
MAPIFolder parentFolder = mapiFolder.Parent as MAPIFolder;
if (parentFolder != null)
{
Folders folders = parentFolder.Folders;
// find our folder
if (folders != null && folders.Count > 0)
{
for (int i = 1; i < folders.Count; i++)
{
MAPIFolder folder = folders;
if (folder.Name == "test")
{
customFolder = folder;
break;
}
}
if (customFolder == null)
{
try
{
customFolder = folders.Add("test", OlDefaultFolders.olFolderInbox);
}
catch (Exception ex)
{
_log.Error(ex);
}
}
Marshal.ReleaseComObject(folders);
}
Marshal.ReleaseComObject(parentFolder);
Marshal.ReleaseComObject(mapiFolder);
Marshal.ReleaseComObject(ns);
}
return customFolder;
}
====================================================
If anyone has any insight as to why I am seeing a difference between cached
exchange mode and non-cached exchange mode, I would greatly appreciate
hearing your thoughts!
Thanks,
Ryan
I am using Outlook 2007 and am attempting to create and later reference a
folder above the Inbox folder. It turns out, that this code works perfectly
when the "Use Cached Exchange Mode" option is unchecked. When it is checked,
the code acts differently in two ways: 1, when looping through the folders,
my custom folder is not found (even though it exists), 2, since the folder is
not found, it attempts to create it, this create attempt fails with an
exception.
The exception is "System.Runtime.InteropServices.COMException (0x80020009):
Cannot create the folder.
at Microsoft.Office.Interop.Outlook.FoldersClass.Add(String Name, Object
Type)"
The code I use is below, basically all the code does is loop through the
list of folders directly above the inbox folder and if it finds our folder it
returns it, if our folder isn't found, then it is created and returned:
====================================================
private MAPIFolder GetCustomFolder()
{
MAPIFolder customFolder = null;
NameSpace ns = _app.Session;
MAPIFolder mapiFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
MAPIFolder parentFolder = mapiFolder.Parent as MAPIFolder;
if (parentFolder != null)
{
Folders folders = parentFolder.Folders;
// find our folder
if (folders != null && folders.Count > 0)
{
for (int i = 1; i < folders.Count; i++)
{
MAPIFolder folder = folders;
if (folder.Name == "test")
{
customFolder = folder;
break;
}
}
if (customFolder == null)
{
try
{
customFolder = folders.Add("test", OlDefaultFolders.olFolderInbox);
}
catch (Exception ex)
{
_log.Error(ex);
}
}
Marshal.ReleaseComObject(folders);
}
Marshal.ReleaseComObject(parentFolder);
Marshal.ReleaseComObject(mapiFolder);
Marshal.ReleaseComObject(ns);
}
return customFolder;
}
====================================================
If anyone has any insight as to why I am seeing a difference between cached
exchange mode and non-cached exchange mode, I would greatly appreciate
hearing your thoughts!
Thanks,
Ryan