C
CodeScribler
Hi All,
I am trying to create a contacts folder in Outlook 2007 programticaly. The
following code fails:
C# 2.0:
private void CreateContactsFolder()
{
Outlook.Application objOutlook;
Outlook.NameSpace objNS;
objOutlook = new
Microsoft.Office.Interop.Outlook.ApplicationClass();
objNS = objOutlook.GetNamespace("MAPI");
// Error occurs on following line
objNS.Folders.Add("ExampleContactsFolder",
Outlook.OlDefaultFolders.olFolderContacts);
// If I try the following line as an alternative it also fails
//objNS.Folders.Add("ExampleContactsFolder",
Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);
}
The error for the first approach is: System.InvalidCastException
The error for the second approach is: Could not complete the operation.
System.ArgumentException: Could not complete the operation. One or more
parameter values are not valid.
Clearly the problem is to do with the 2nd argument but I am foxed. Any ideas?
Any ideas?
I am trying to create a contacts folder in Outlook 2007 programticaly. The
following code fails:
C# 2.0:
private void CreateContactsFolder()
{
Outlook.Application objOutlook;
Outlook.NameSpace objNS;
objOutlook = new
Microsoft.Office.Interop.Outlook.ApplicationClass();
objNS = objOutlook.GetNamespace("MAPI");
// Error occurs on following line
objNS.Folders.Add("ExampleContactsFolder",
Outlook.OlDefaultFolders.olFolderContacts);
// If I try the following line as an alternative it also fails
//objNS.Folders.Add("ExampleContactsFolder",
Microsoft.Office.Interop.Outlook.OlItemType.olContactItem);
}
The error for the first approach is: System.InvalidCastException
The error for the second approach is: Could not complete the operation.
System.ArgumentException: Could not complete the operation. One or more
parameter values are not valid.
Clearly the problem is to do with the 2nd argument but I am foxed. Any ideas?
Any ideas?