Dear all,
I'm a newbie Outlook Add-in and I have developed a small Outlook Add-in, but now I have an issue with the Add-in. Sample source code is bellow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
void Application_ItemSend(object Item, ref bool Cancel)
{
Outlook._MailItem mailItem = (Outlook._MailItem)Item;
try
{
string strTempFileName = string.Empty;
string strTempPath = Path.GetTempPath();
DateTime dtCurrent = DateTime.Now;
strTempFileName = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}",
dtCurrent.Year,
dtCurrent.Month,
dtCurrent.Day,
dtCurrent.Hour,
dtCurrent.Minute,
dtCurrent.Second,
dtCurrent.Millisecond);
strTempFileName = strTempPath + strTempFileName + ".oft";
mailItem.SaveAs(strTempFileName, Outlook.OlSaveAsType.olTemplate);
File.Delete(strTempFileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Marshal.ReleaseComObject(mailItem);
}
Cancel = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
Pre-condition:
1. There is at least one item in Draft folder.
Steps to procedure issue:
1. Start MS Outlook
2. Open an item in Draft folder
3. Click button [Send]
4. Close editor of current item. At this time, a message box is displayed [Do you want to save changes?] although I did not make any change.
5. Close MS Outlook. At this time, another message box is displayed [Do you want to save changes?] two times.
Question:
1. Why [Do you want to save changes?] message is displayed?
2. How can I disable the [Do you want to save changes?] message without calling MailItem.Save method?
(I'm using WinXP + MS Outlook 2010 + Visual Studio 2010 to develop the Add-in.)
Thanks for helping.