Sunday, January 24, 2010

Creating a Outlook store programatically

Office programming has become much easier with Visual Studio for Office. Though the object model still needs to be know, but there is less of COM plumbing, and helper classes to make life easier .
Among the entire Office suite family, Outlook is probably the most used , and hence users prefer addins which can connect to other external applications, be it CRM or fetching data from web service and displaying in the Outlook dashboard
If you are really serious about Office Development,  you should get a copy of Add In Express, which makes office development very easy .  The Addin Express team has been kind enough to provide a 10% discount to the readers of this blogs and so you can grab a copy of Add In Express ( Standard , Professional, Premium ) at http://www.add-in-express.com/purchase/index.php using the discount coupon ADX-GSUJAY-ADX10.

The following code creates a MAPIStore programmmatically. I have used C# as the language. Though I have worked with MAPI , ( Simple and Extended MAPI ) with C++/COM, if you dont need Extended MAPI , C# is just fine . But again remember , that the entire Office Suie is unmanaged code, and C# is managed code , so you may have to do marshalling sometimes .


Outlook.NameSpace olNamespace = OutlookApp.GetNamespace("MAPI");
// Get the Default Inbox folder
Outlook.MAPIFolder olMapiFolder = olNamespace.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

Outlook.MAPIFolder olCustomFolder;               
string path = "C:\\mydata.pst";
// Create a store



olNamespace.AddStore(path);
// Get the last folder
olCustomFolder = olNamespace.Session.Folders.GetLast();
// If you want the user to choose a folder you can replace the above line with the following
olCustomFolder = olNaameSpace.PickFolder( );
olCustomFolder.Name = "My Inbox";
olCustomFolder.Description = "This folder is my inbox ";


Stay tuned on more on Office Development .

No comments :