Creating Folder Issue

Add-in Express™ Support Service
That's what is more important than anything else

Creating Folder Issue
 
Rup Go




Posts: 64
Joined: 2007-03-01
Hi,

the code here seems to work on adding a folder + subfolder, but the problem here is sometimes when i restart outlook, it throws an error that points to this method below, maybe because the folder was already created when outlook was first launch?

private void CreateAddinExpressFoldersAndItems()
{
Outlook.MAPIFolder rootFolder = null;
Outlook.MAPIFolder adxFolder = null;
Outlook.Explorer exp = OutlookApp.ActiveExplorer();


try
{
rootFolder = Utils.OutlookManager.GetRootFolder(OutlookApp);
if (rootFolder != null)
{
adxFolder = Utils.OutlookManager.CreateFolder("CMS", rootFolder, Outlook.OlDefaultFolders.olFolderInbox);
mailFolder = Utils.OutlookManager.CreateFolder("Group Folder", adxFolder, Outlook.OlDefaultFolders.olFolderInbox);

if (adxFolder != null)
{
adxOlFormsManager1.Items[0].FolderName = rootFolder.Name + '\\' + adxFolder.Name;
}
}
}
finally
{
if (rootFolder != null)
{
Marshal.ReleaseComObject(rootFolder);
}
if (adxFolder != null)
{
Marshal.ReleaseComObject(adxFolder);
}
}
}

private void adxOlFormsManager1_OnInitialize()
{
CreateAddinExpressFoldersAndItems();
}

thanks!
Posted 04 May, 2007 04:01:57 Top
Fedor Shihantsov


Guest


Hi Rup,

Define in the debugger mode what a line throws an error.
If it is CreateFolder then use the MAPIFolder.Folders property to check availability of a folder.

Pseudocode:
try
{
requiredFolder = rootFolder.Folders("CMS");
}
catch
{
requiredFolder = null;
}

//It is the alternative without the try/catch block
//ForEach(folder in rootFolder.Folders)
//{
// if (folder.Name == "CMS")
// {
// requiredFolder = folder;
// break;
// }
//}


if (requiredFolder == null)
{
requiredFolder = CreateFolder;
}

P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 04 May, 2007 05:35:43 Top
Rup Go




Posts: 64
Joined: 2007-03-01
thanks Fedor, hopefully it won't gave me the error again ^^
Posted 07 May, 2007 02:43:55 Top
Rup Go




Posts: 64
Joined: 2007-03-01
Hi Fedor,

i still got the error, but it is strange though, whenever i restart outlook close it then restart it again, along the way approx 10x of opening outlook, the error pops out. and now the problem here is this method, i assume u guys know utils.OutlookManager.cs:

public static Outlook.MAPIFolder GetRootFolder(Outlook._Application application)
{
Outlook.MAPIFolder result = null;
Outlook.MAPIFolder inboxFolder = null;
object parent = null;
try
{
inboxFolder = OutlookManager.GetDefaultFolder(application, Outlook.OlDefaultFolders.olFolderInbox);
if (inboxFolder != null)
{
parent = inboxFolder.Parent;
if (parent != null)
{
result = parent as Outlook.MAPIFolder;
parent = null;
}
}
return result;
}
finally
{
if (inboxFolder != null)
{
Marshal.ReleaseComObject(inboxFolder);
}
if (parent != null)
{
Marshal.ReleaseComObject(parent);
}
}
}

thanks!
Posted 08 May, 2007 04:45:47 Top
Fedor Shihantsov


Guest


Hi Rup,

What error do you get?

What line raises error?
Posted 08 May, 2007 10:30:31 Top
Rup Go




Posts: 64
Joined: 2007-03-01
Detailed technical information follows:
---
Date and Time: 5/9/2007 12:07:54 PM
Machine Name: RUP
IP Address: 192.168.1.100
Current User: RUP\Ruff

Application Domain: C:\Documents and Settings\Ruff\My Documents\Visual Studio 2005\Projects\CMS\CMS_Outlook\bin\Debug\
Assembly Codebase: file:///C:/WINDOWS/assembly/GAC_MSIL/AddinExpress.OL.2005/3.4.906.2005__e69a7e0f3592d2b8/AddinExpress.OL.2005.dll
Assembly Full Name: AddinExpress.OL.2005, Version=3.4.906.2005, Culture=neutral, PublicKeyToken=e69a7e0f3592d2b8
Assembly Version: 3.4.906.2005
Assembly Build Date: 6/25/2002 1:06:50 AM

Exception Source: Microsoft Office Outlook
Exception Type: System.Runtime.InteropServices.COMException
Exception Message: The messaging interface has returned an unknown error. If the problem persists, restart Outlook.
Exception Target Site: get_Parent

---- Stack Trace ----
Microsoft.Office.Interop.Outlook.MAPIFolder.get_Parent()
AddinExpress.OL.2005.dll: N 00000 (0x0) JIT
Utils.OutlookManager.GetRootFolder(application As _Application)
OutlookManager.cs: line 0062, col 21, IL 0027 (0x1B)
CMS_Outlook.AddinModule.CreateAddinExpressFoldersAndItems()
AddinModule.cs: line 0256, col 17, IL 0026 (0x1A)
CMS_Outlook.AddinModule.adxOlFormsManager1_OnInitialize()
AddinModule.cs: line 0300, col 13, IL 0001 (0x1)
AddinExpress.OL.ADXOlFormsManager.DoAddinInitialize(sender As Object, ea As EventArgs)
AddinExpress.OL.2005.dll: N 0175 (0xAF) IL



line 062 is
inboxFolder = OutlookManager.GetDefaultFolder(application, Outlook.OlDefaultFolders.olFolderInbox);

this is the exact error popup shown.
Posted 09 May, 2007 00:27:02 Top
Fedor Shihantsov


Guest


I can not reproduce this error with the HelloWorld example on my Outlook 2003 (11.8118.8122) SP2 and Outlook 2007 (12.0.4518.1014)

What Outlook version (including build) do you use?

Could you please send me your project on the support email for testing?
Posted 10 May, 2007 05:07:40 Top
Rup Go




Posts: 64
Joined: 2007-03-01
Hi Fedor,

i think i just fixed it, just put some Marshal.ReleaseComObject of a folder variable and the error doesn't show anymore. My fault i guess ^_^

thanks!
Posted 11 May, 2007 02:44:55 Top