D
Dilum
Our application converts various text document formats to text files. Users
can use the application to select a supported file (doc, pdf, msg etc.) to
generate a text file (.txt) .
But there is an issue with converting Outlook message files (.msg) to text
files. When trying to read the msg file with an Outlook object, a pop-up
window comes from Outlook saying that a program is trying to access Outlook.
So the users always have to grant access to the application whenever they try
to generate a text file from msg files.
The code block is shown below.
The variable “path†contains the file path to the message file.
// Create Outlook Application Object
Microsoft.Office.Interop.Outlook.ApplicationClass objOutlook =
newMicrosoft.Office.Interop.Outlook.ApplicationClass();
//Create Null Ref Object
object nullobj = System.Reflection.Missing.Value;
// Outlook Mail Object
Microsoft.Office.Interop.Outlook.MailItem msgItem;
// Open Mail file
msgItem =
(Microsoft.Office.Interop.Outlook.MailItem)objOutlook.CreateItemFromTemplate(path,nullobj);
// Extract Plain Text
string plainText = msgItem.Body.ToString();
// Cleanup Resources.
objOutlook.Quit();
objOutlook = null;
return plainText;
The application uses COM INTEROPS of Office XP, Office 2003 and Office 2007
to generate text files. First, the available version is checked and then uses
INTEROPS of that particular version to generate text files.
The application doesn’t need to access the Outlook application, because
users select a file available in the local file system using a file-open
dialog box.
We need to find a solution to stop appearing the pop-up warning so that
users don’t have to respond to the warning message.
can use the application to select a supported file (doc, pdf, msg etc.) to
generate a text file (.txt) .
But there is an issue with converting Outlook message files (.msg) to text
files. When trying to read the msg file with an Outlook object, a pop-up
window comes from Outlook saying that a program is trying to access Outlook.
So the users always have to grant access to the application whenever they try
to generate a text file from msg files.
The code block is shown below.
The variable “path†contains the file path to the message file.
// Create Outlook Application Object
Microsoft.Office.Interop.Outlook.ApplicationClass objOutlook =
newMicrosoft.Office.Interop.Outlook.ApplicationClass();
//Create Null Ref Object
object nullobj = System.Reflection.Missing.Value;
// Outlook Mail Object
Microsoft.Office.Interop.Outlook.MailItem msgItem;
// Open Mail file
msgItem =
(Microsoft.Office.Interop.Outlook.MailItem)objOutlook.CreateItemFromTemplate(path,nullobj);
// Extract Plain Text
string plainText = msgItem.Body.ToString();
// Cleanup Resources.
objOutlook.Quit();
objOutlook = null;
return plainText;
The application uses COM INTEROPS of Office XP, Office 2003 and Office 2007
to generate text files. First, the available version is checked and then uses
INTEROPS of that particular version to generate text files.
The application doesn’t need to access the Outlook application, because
users select a file available in the local file system using a file-open
dialog box.
We need to find a solution to stop appearing the pop-up warning so that
users don’t have to respond to the warning message.