Programming Outlook 2003 with C#...folders problems

  • Thread starter Thread starter Paulos
  • Start date Start date
P

Paulos

I am trying to make improvements to an app I wrote a while back in C#.

What I want to do is to move an email message from the Inbox to another
folder within the inbox that I have created called 'JS Archive'.


NameSpace objOLNS = objOL.GetNamespace("MAPI");
MAPIFolder objInbox =
objOLNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

The above code gives me access to the inbox but I cannot figure out how
I get access to folders that I create (i.e. not one of the default folders)

Anyone out there know how this is done?

Secondly, anyone know how to move an email from one folder to another.

Cheers

Paul BJ
 
Hello Paulos,

MAPIFolder otherFolder = objInbox.Folders["JS Archive"];

or first get ParentFolder

MAPIFolder parentFolder = objInbox.Parent // the Store
MAPIFolder otherFolder = parentFolder .Folders["JS Archive"];

that should do the trick.

--
regards

Helmut Obertanner
Technical Consultant

Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web: www.datalog.de


.... and IT works!
 
Helmut said:
Hello Paulos,

MAPIFolder otherFolder = objInbox.Folders["JS Archive"];

or first get ParentFolder

MAPIFolder parentFolder = objInbox.Parent // the Store
MAPIFolder otherFolder = parentFolder .Folders["JS Archive"];

that should do the trick.
Damn, Damn, DAMN!

Thats the second time I have been held up for the same reason...trying
to use ()s when in C# I need []s.

Clearly I have been programming in VB and VBA for too long and I have
been neglecting my C based languages!

Thanks!

Paul BJ
 
Hello Paulos,
Second question:

MAPIFolder objInbox = objOLNS.GetDefaultFolder
olDefaultFolders.olFolderInbox);
MAPIFolder otherFolder = objInbox.Folders["JS Archive"];

foreach (object item in objInbox.Items)
{
if (item == MailItem)
{
MailItem mailItem = (MailItem) item;
if (mailItem.Subject.StartsWith("JS"))
{
mailItem.Move(otherFolder);
}
Marshal.ReleaseComObject(mailItem);
}

}

Marshal.ReleaseComObject(otherFolder );
Marshal.ReleaseComObject(objInbox);
GC.Collect();

--
Freundliche Grüße / regards

Helmut Obertanner
Technical Consultant

Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web: www.datalog.de


.... and IT works!
 
Back
Top