using System; using System.Collections.Generic; using System.Text; using System.Reflection; using Microsoft.Win32; using System.Globalization; namespace cdsOutlook { public class cdsOutlook : IDisposable { private bool IsDisposed=false; public static Outlook.Application oApp; public static Outlook.NameSpace oNS; public static Outlook.MAPIFolder oInbox; public static Outlook.Items oItems; public static Outlook.MailItem oMsg; /// <summary> /// Fix this routine to be the constructor */*/*/*/*/*/* /// </summary> /// <param name="args"></param> /// <returns></returns> public static int Temp() { try { // Create the Outlook application. // in-line initialization oApp = new Outlook.Application(); // Get the MAPI namespace. oNS = oApp.GetNamespace("mapi"); // Log on by using the default profile or existing session (no dialog box). oNS.Logon(Missing.Value, Missing.Value, false, true); // Alternate logon method that uses a specific profile name. // TODO: If you use this logon method, specify the correct profile name // and comment the previous Logon line. //oNS.Logon("profilename",Missing.Value,false,true); //Get the Inbox folder. oInbox = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); //Get the Items collection in the Inbox folder. oItems = oInbox.Items; // Get the first message. // Because the Items folder may contain different item types, // use explicit typecasting with the assignment. oMsg = (Outlook.MailItem)oItems.GetFirst(); } //Error handler. catch (System.Exception e) { //Console.WriteLine("{0} Exception caught: ", e); } //Console.ReadLine(); // Return value. return 0; } /// <summary> /// Is Outlook Installed /// </summary> /// <returns>bool</returns> private bool IsOutlookInstalled() { Type requestType = Type.GetTypeFromProgID("Outlook.Application", false); if (requestType == null) { RegistryKey key = null; try { key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office", false); if (key != null) { double version = 0.0, temp = 0.0; string[] valueNames = key.GetSubKeyNames(); for (int i = 0; i < valueNames.Length; i++) { temp = 0.0; try { temp = Convert.ToDouble(valueNames[i], CultureInfo.CreateSpecificCulture("en-US").NumberFormat); } catch { } if (temp > version) version = temp; } key.Close(); if (version != 0.0) requestType = Type.GetTypeFromProgID("Outlook.Application." + version.ToString().Replace(",", "."), false); } } catch { if (key != null) key.Close(); } } return (requestType != null); } /// <summary> /// Get Office Version /// </summary> /// <returns>int Version Number</returns> private int GetOfficeVersion() { RegistryKey key = null; try { key = Registry.ClassesRoot.OpenSubKey("Outlook.Application\\CurVer", false); if (key != null) { string version = key.GetValue("", "Outlook.Application.9").ToString(); key.Close(); int pos = version.LastIndexOf("."); if (pos >= 0) { version = version.Remove(0, pos + 1); return Convert.ToInt32(version); } } } catch (Exception e) { // */* need error handler if (key != null) key.Close(); //module.DoError(e); } return 9; } /// <summary> /// Explicit Dispose - Close Outlook, call prior to release. /// </summary> public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// Internal Destructor Code protected void Dispose(bool Disposing) { if(!IsDisposed) { if(Disposing) { // */* Clean up managed resources } // */* Clean up unmanaged resources //Log off. oNS.Logoff(); //Explicitly release objects. oMsg = null; oItems = null; oInbox = null; oNS = null; oApp = null; } IsDisposed=true; } /// Destructor ~cdsOutlook() { Dispose(false); } } }