1
Reply

Outlook Appointments and Late Binding

simon

simon

Sep 30 2010 5:26 AM
11.3k
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.

 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.");
                return new StringList();
            }
            oApp = Activator.CreateInstance(OutlookType);

            object oNameSpace = oApp.GetType().InvokeMember("GetNamespace", BindingFlags.InvokeMethod, null, oApp, new object[1] { "MAPI" });
            //MethodInfo mi1 = oNameSpace.GetType().GetMethod("GetDefaultFolder");
            //9..eigener Kalender
            for (int i = 0; i < 30; i++)
            {
               
                try
                {
                    object objDefaultFolder = oNameSpace.GetType().InvokeMember("GetDefaultFolder", BindingFlags.InvokeMethod, null, oNameSpace, new object[] { 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 binding
                                object 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)
                {
               
                }
               
            }



Answers (1)