The way to do this is to use Office PIA.
Microsoft.Office.Interop.Outlook namespace is the one you want.
I was able to update my contacts from AS400, but I set it up for a one
time shot. I'm sure there is a more advanced way to do a daily sync. I
wonder if outlook COM automation would perform from a Windows Service.
I guess not:
http://bytes.com/topic/visual-basic-net/answers/671099-windows-service-o
utlook
Looks like the only way I can find is using the MS Replication API and
probably this
http://openmapi.org/nmapi. Someone correct me if I'm
wrong please.
Here is a class that should help interface with OL:
public class ol
{
private Application olApp;
private NameSpace olNs;
private MAPIFolder olF;
private System.Collections.Specialized.NameValueCollection
entries;
private MAPIFolder olWorkingF;
public OlItemType wfItemType
{
get
{
return olWorkingF.DefaultItemType;
}
}
public int wfCount
{
get
{
try
{
return olWorkingF.Items.Count;
}
catch (System.Exception ex)
{
return 0;
}
}
}
public object wfObject(int index)
{
try
{
return olWorkingF.Items[index];
}
catch (System.Exception ex)
{
return null;
}
}
#region ctor
public ol(string StoreName)
{
olApp = new Application();
olNs = olApp.GetNamespace("MAPI");
entries = new
System.Collections.Specialized.NameValueCollection();
try
{
Console.WriteLine("Looking for store: " + StoreName);
olF = FindStoreByName(StoreName);
}
catch { }
if (olF == null)
{
Console.WriteLine("Store '" + StoreName + "' not found!
");
}
else
{
Console.WriteLine(" > " + olF.FullFolderPath + " [" +
olF.DefaultItemType + "] : " + olF.Folders.Count);
EntriesBuilder(olF,1);
Console.WriteLine("");
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
public void finish()
{
try
{
Console.WriteLine("Closing Outlook.");
olApp.Quit();
olNs.Logoff();
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(olApp);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(olNs);
olApp = null;
olNs = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endregion ctor
#region Folder Methods
public void setWorkingFolder(string foldername)
{
string id = getEntryId(foldername);
if (id != null)
{
olWorkingF = null;
olWorkingF = olNs.GetFolderFromID(id, olF.StoreID);
if (olWorkingF != null)
{
Console.WriteLine("Working Folder : " +
olWorkingF.FullFolderPath);
}
else
{
Console.WriteLine("Unable to set working folder : "
+ foldername);
}
}
else
{
Console.WriteLine("Unable to retrieve ID for working
folder : " + foldername);
}
}
private void EntriesBuilder(MAPIFolder someFolder, int indent)
{
indent++;
string s = "";
for (int i = 1; i <= someFolder.Folders.Count; i++)
{
MAPIFolder olFi = someFolder.Folders[i];
Console.WriteLine(s.PadRight(indent) + "> " + olFi.Name
+ " [" + olFi.DefaultItemType + "] ");
entries.Add(olFi.EntryID, olFi.Name);
if (olFi.Folders.Count > 0)
{
EntriesBuilder(olFi, indent);
}
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(olFi);
olFi = null;
}
}
private string getEntryId(string folderName)
{
if (entries.Count > 0)
{
for (int i = 0; i < entries.Count; i++)
{
if (entries.GetValues(i)[0].ToLower() ==
folderName.ToLower())
{
return entries.GetKey(i);
}
}
}
return null;
}
#endregion
#region Store Methods
private MAPIFolder FindStoreByName(string folderName)
{
MAPIFolder returnItem = null;
System.Collections.IEnumerator folderEnum =
olNs.Folders.GetEnumerator();
while (folderEnum.MoveNext())
{
MAPIFolder curFolder = (MAPIFolder)folderEnum.Current;
if (curFolder.Name.ToLower() == folderName.ToLower())
{
returnItem = curFolder;
break;
}
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(curFolder);
}
//
http://blogs.msdn.com/mstehle/archive/2007/12/07/oom-net-part-2-outlook-
item-leaks.aspx
//foreach (MAPIFolder olF in olNs.Folders)
//{
// if (olF.Name.ToLower() == folderName.ToLower())
// {
// return olF;
// }
//}
System.Runtime.InteropServices.ICustomAdapter adapter =
(System.Runtime.InteropServices.ICustomAdapter)folderEnum;
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(adapter.Get
UnderlyingObject());
return returnItem;
}
#endregion
}
}
-----Original Message-----
From: systemidotnet-bounces@xxxxxxxxxxxx
[mailto:systemidotnet-bounces@xxxxxxxxxxxx] On Behalf Of Wyatt Repavich
Sent: Tuesday, December 29, 2009 11:26 AM
To: systemidotnet@xxxxxxxxxxxx
Subject: [SystemiDotNet] Batch processing csv import to Outlook Calendar
Hello All -
The latest post about using a .csv to transfer a contact list got me
thinking about a recent request for a process to synchronize a System i
appointment scheduler with an Outlook Calendar (2003/2007). I want to
import and export through a nightly process. I plan to use .csv files
for
the synchronization. Does Outlook have import/export commands that can
be
run in a .bat? Is there a more elegant way to get this done? If anyone
has
insight, I would appreciate the help.
Thanks.
- Wyatt Repavich
As an Amazon Associate we earn from qualifying purchases.