is this code correct to create a new post item...

sfilepath=@""C:\Documents and Settings\example.msg";
Outlook._PostItem omail = (Outlook._PostItem)olApp.CreateItemFromTemplate(sfilepath,Type.Missing);

am new to this and mainly doesnot know the difference between mailitem and postitem..but when i create a mailitem the code rus successfully.But when using postitem it shows the below exception..


Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook._PostItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063024-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
So then how can i create a postitem ???

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

>mainly doesnot know the difference between mailitem and postitem.

From MSDN article.

SUMMARY:
PostItem represents a post in a public folder that others may browse. Unlike a MailItem object, a PostItem object is not sent to a recipient. You use the Post method, which is analogous to the Send method for the MailItem object, to save the PostItem to the target public folder instead of mailing it.

Outlook._ContactItem omail = (Outlook._ContactItem)olApp.CreateItemFromTemplate(sfilepath,Type.Missing);

Hi, thanks for replying..i tried this..but it too shows the same exception....

>but it too shows the same exception....

Sorry! I am not a magician. You wrote that program and you should be able to figure out why it's not doing what you want.

>but it too shows the same exception....

Sorry! I am not a magician. You wrote that program and you should be able to figure out why it's not doing what you want.

k....i will try...thanks for replying....

This question has already been answered. Start a new discussion instead.