Create an Outlook Appointment and set the Label - with CDO in C# - Problems

B

berend.kapelle

Hi,
i found this code from outlookcode.com
http://www.outlookcode.com/codedetail.aspx?id=139

Its written in VB, and i have some problem porting it to C#.

The problem is getting the right appointment. An Exception occurs in
this line:
MAPI.Field oField = (MAPI.Field) oFields.get_Item(CdoAppt_Colors,
CdoPropSetID1);

My Code so far:
Microsoft.Office.Interop.Outlook.AppointmentItem appItem =
(Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(OlItemType.olAppointmentItem);
appItem.Body = "Test!";

DateTime now = DateTime.Now; // start and end time
appItem.Start = now.AddHours(1);
appItem.End = now.AddHours(2);
appItem.Subject= "This is a test";
appItem.Save();


Object vEmpty = Missing.Value;


MAPI.Session oSession = new MAPI.Session();
oSession.Logon(vEmpty, vEmpty, true, true, 0, true, vEmpty);


const string CdoPropSetID1 = "0220060000000000C000000000000046"; //
const string CdoAppt_Colors = "0x8214"; // label property

MAPI.Folder oFolder =
(MAPI.Folder)oSession.GetDefaultFolder(MAPI.CdoDefaultFolderTypes.CdoDefaultFolderCalendar);

MessageBox.Show("Folder: "+ oFolder.Name);


if(appItem.EntryID!="")
{
MAPI.Fields oFields = (MAPI.Fields)oFolder.Fields;
MAPI.Field oField = (MAPI.Field) oFields.get_Item(CdoAppt_Colors,
CdoPropSetID1);

if(oField == vEmpty)
{
oFields.Add(CdoAppt_Colors, vEmpty, 2, CdoPropSetID1); // 2 is for
the second label
}
else
{
oField.Value = 2; // 2 is for the second label
}
}
 

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