Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Outlook PST FIles in C#

Status
Not open for further replies.

qa230001

Programmer
Joined
Aug 21, 2006
Messages
1
Location
US
Hi Forum Members,

I am trying to read the outlook files "pst" and load them in my application, I dont know where to start and how to start. So is there any body that can give me a start point and help me doing this?

I would like to do this in C# (VS 2003).

Regards,

QAKiani.
 
I have used this to access emails in my own personal Outlook folder. I hope this at least guides you in the right direction.

First I set a reference in my project from the COM table to Microsoft Outlook. I include these using statements.

The thing I haven't figured out is how to get rid of original warning box on the opening of emails. Maybe someone can help me out on this. But the great thing about this is that at least it works!

Code:
using Outlook;
using System.Runtime.InteropServices;

private void button1_Click(object sender, System.EventArgs e)
		{
			Outlook.Application app = new Outlook.ApplicationClass();
			Outlook.NameSpace NS = app.GetNamespace("MAPI");
			Outlook.MAPIFolder objFolder = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
			Outlook.MailItem objMail;

			Outlook.Items oItems;
			oItems = objFolder.Items;

			try
			{
				for (int i=1; i<objFolder.Items.Count;i++)
				{

					objMail = (Outlook.MailItem)oItems.Item(i);
					MessageBox.Show(objMail.Body.ToString());				

				}
			}
			catch(COMException ex)
			{
				MessageBox.Show(ex.Message);
			}
			finally
			{
				NS.Logoff();
				objFolder = null;
				objMail = null;
				app = null;
			
			
			}
		}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top