How to create a user-defined field in vsto

E

eranhef

Hey,
I'm trying to programmatically create a user-defined field to a new
calendar folder that my application creates.

Can anyone help me?
I'm using vsto 2005 + C#.

Attached by the folder creation method:
private bool CreateSstFolder(string folderName,ThisApplication app)
{
Outlook.NameSpace mapi = app.GetNamespace("MAPI");
Outlook.MAPIFolder calendar =
mapi.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as
Outlook.MAPIFolder;
Outlook.MAPIFolder targetFolder = null;
Outlook.MAPIFolder newFolder = null;
if ( calendar != null && calendar.Parent is Outlook.MAPIFolder)
{
//Outlook.MAPIFolder rootFolder =
(Outlook.MAPIFolder)calendar.Parent;
Outlook.MAPIFolder rootFolder = calendar;
if( rootFolder != null )
{
foreach (Outlook.MAPIFolder folder in rootFolder.Folders)
{
if (folder.Name.Equals(folderName))
{
targetFolder = folder;
break;
}
}
if( targetFolder == null )
{
newFolder = rootFolder.Folders.Add(folderName,
System.Reflection.Missing.Value);

return true;
}
}
}
return false;
}


Tnx in advance -
Eran Hefer.
 
S

Sue Mosher [MVP-Outlook]

Create a new appointment in that new folder and use the appointment's Userproperties.Add method to add a new property to both the appointment and the folder, setting the third parameter of Add to True. You can then delete the appointment.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
E

eranhef

Hey,
it gives me this exception:
"Type mismatch. (Exception from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH))"

I'm using this code:
Outlook.AppointmentItem item =
(Outlook.AppointmentItem)newFolder.Items.Add(1);
item.UserProperties.Add(FieldName,
Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, true, "");

'FieldName' is a string variable.
The application fails in the second row.

I want to thank to for your quick response.

Best Regards,
Eran Hefer.
 

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