Hello, i have a short programm which uses late binding to read the appointments from Outlook. But now i want to add an appointment. How can i do this with late binding?? My Programm with early binding functions very good but now i have to use it with other versions of office.
Below is the code and i`m standing at the point where //...????
I hope you can help me and that i post enough information.
C#
StringList ls = new StringList();
Type OutlookType;
object oApp;
object CalendarFolder;
OutlookType = Type.GetTypeFromProgID("Outlook.Application");
if (OutlookType == null)
{
MessageBox.Show("MS-Outlook ist nicht installiert.");
returnnew StringList();
}
oApp = Activator.CreateInstance(OutlookType);
object oNameSpace = oApp.GetType().InvokeMember("GetNamespace", BindingFlags.InvokeMethod, null, oApp, newobject[1] { "MAPI" });
//MethodInfo mi1 = oNameSpace.GetType().GetMethod("GetDefaultFolder");//9..eigener Kalenderfor (int i = 0; i < 30; i++)
{
try
{
object objDefaultFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder", BindingFlags.InvokeMethod, null, oNameSpace, newobject[] { i });
object objFolderItems = objDefaultFolder.GetType().InvokeMember("Folders", BindingFlags.InvokeMethod, null, objDefaultFolder, null);
int numofentries = (int)objFolderItems.GetType().InvokeMember("Count", BindingFlags.InvokeMethod, null, objFolderItems, null);
object curObj = objFolderItems.GetType().InvokeMember("GetLast", BindingFlags.InvokeMethod, null, objFolderItems, null);
// string strpf = (string)objContactItems.GetType().InvokeMember("FolderPath", BindingFlags.InvokeMethod, null, objContactItems, null);//ls.Add(strpf);try
{
string foldername = (String)curObj.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, curObj, null);
if(foldername.Contains("Termine Schule")) //when this directory is found
{
ls.Add(foldername);
ls.Add(i.ToString());
ls.Add(numofentries.ToString());
try
{
object objCalendarItems = curObj.GetType().InvokeMember("Items", BindingFlags.InvokeMethod, null, curObj, null);
int numofItems = (int)objCalendarItems.GetType().InvokeMember("Count", BindingFlags.InvokeMethod, null, objCalendarItems, null); //aktual count of Entries in the Calendar//Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookCalendarItems.Add(Outlook.OlItemType.olAppointmentItem); //add appointment without late bindingobject testobj=objCalendarItems.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objCalendarItems, new Object[] { "test" }); //my trying//...????
ls.Add(numofItems.ToString());
}
catch (Exception ex)
{
ls.Add(ex.Message);
}
}
}
catch
{
}
}
catch(Exception ex)
{
}
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
you wrote: //Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookCalendarItems.Add(Outlook.OlItemType.olAppointmentItem); //add appointment without late binding
Sebastian36 reputationPosted Sep 26, 2011, 3:08 PM EDT
//Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookCalendarItems.Add(Outlook.OlItemType.olAppointmentItem); //add appointment without late binding
object testobj=objCalendarItems.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objCalendarItems, new Object[] { "test" }); //my trying
your problem is the parameter "test" of course.
you have to give Outlook.OlItemType.olAppointmentItem means 1
an easier way for version independent office programming in .NET is
NetOffice: http://netoffice.codeplex.com
same syntax as early bind interop but version independent and without deployment trouble.