I have an outlook addin which shows a popup after sending mail which asks the user whether he/she wants to save the mail.
The problem is that this popup is shown when a mail is added to the sent folder.
So when you send a mail and immediately start dragging a mail to another folder because, e.g. you want to clean up mails, then the popup shows when you're in the middle of dragging which stops the dragging and makes the popup with the question unresponsive to the mouse.
Is there any way around this?
Thanks in advance!
The event for an mail being added to sent folder is set in the Ribbon Load method:
private void CodexRibbon_Load(object sender, RibbonUIEventArgs e)
{
if (!Globals.ThisAddIn.FirstLoadComplete)
{
Messenger.Default.Register<object>(this, ItemSend);
Globals.ThisAddIn.FirstLoadComplete = true;
}
}
The question is asked as follows:
private void ItemSend(object item)
{
if (MessageBox.Show(#" Wilt u de zojuist verzonden e-mail opslaan?", #"Opslaan in Codex", MessageBoxButtons.YesNo) == DialogResult.Yes)
ShowSaveWindow(item);
}
I don't think there is a way to find out if the control is inside the DoDragDrop Windows API function (you can patch it and have the patched version set some kind of a global flag before entering the original function, but I don't think that will be a good idea in .Net).
Try to display the message box in the Application.ItemSendevent handler, mark the message somehow (user property?), then do the processing in Items.ItemAdd without a message box.
Related
I am trying to create plug-in that will catch any send item and show warning before sent out.
Currently I am using the below code
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = Globals.ThisAddIn.Application;
application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
However, I noticed it catches almost all the send event but when send button is pressed from main screen of Outlook, I mean when the mail is not popped out to separate window, it does not catch the event and my plugin function is not executed. My environment is Visual Studio 2019 and Outlook 2019. Any advise is appreciated.
Thank you,
Catch all the send event from Outlook.
Update 11/7/2022: it turned out that the event is caught but
I am tryning to catch the item type by the below method and inline item does not detected as an item.
itemtype = Application.ActiveWindow().CurrentItem.Class;
I can confirm that the ItemSend event is fired for all outgoing emails in Outlook, including inline responses. To make sure I've just created a sample VSTO add-in and placed your code there. Everything works correctly when I reply to items in-place. Try to declare the Application object at the class level. But I think everything should work as is now.
Outlook.Application application = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
application = Globals.ThisAddIn.Application;
application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
You may consider subscribing to the Explorer.InlineResponse event which is fired when the user performs an action that causes an inline response to appear in the Reading Pane. So, you may get the item composed and do whatever you need (subscribe to the Send event).
Be aware, a low level API such as Extended or Simple MAPI doesn't trigger the ItemSend event in Outlook - only actions made in the Outlook object model or made manually can trigger the event.
It should work in all cases, but Outlook disables most OOM events for the items created using Simple MAPI or from the "mailto:" links. Is that the case?
I have a custom task pane for my Excel VSTO addin. In this task pane I want to display a clickable link (for example "https://stackoverflow.com") to the user which opens the user's browser and navigates to the site when clicked. When I programmatically put the text into the task pane's RichTextBox the text turns blue as if it is being recognized as a URL, however when the text is clicked on nothing happens. Is there a property I need to set for the RichTextBox to allow the link to be clicked on?
You need to handle the LinkClicked event of the RichTextBox.
richTextBox1.LinkClicked += richtextBox1_LinkClicked;
public void richtextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
// Opens the link in the default browser.
Process.Start(e.LinkText);
}
I am working on a program that auto saves a Microsoft Office document after specific time (loop).
On a click of a button it will activate timer and after a given time delay it should send CTRL+S to Word and save the document.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
startTimer.Enabled = true;
stratTimer.Start();
}
private void startTimer_Tick(object sender, EventArgs e)
{
SendKeys.SendWait("^{s}");
MessageBox.Show("doc auto saved");
}
The problem is that SendKeys.Send("^{s}"); does not work.
How can I accomplish that?
SendKeys.SendWait sends keystrokes to the currently active window, so the keystrokes can be received by other window, like browser (if you are viewing this answer while the automation exe is running in the background). It is not a wise idea to send key strokes to arbitrary window.
This can partially explain why your code does not work in some cases. And it has other issues.
Just as MickyD's comment, don't use this "SendKeys" solution for automation nowadays. For auto save, VSTO is the right way to go.
See How to: Programmatically save documents.
I have a custom add in for Outlook, there is a ribbon and it has a button "Send Info", when i click it, it opens a WPF form which has a save and cancel buttons, when the save is clicked it grabs a list of phone numbers and sends it via Http post to an application that saved them. The problem is that, if the user click on "Cancel", it should cancel the whole process at any point.. What is happening is that when you click Save, it will send whatever is there and if cancel is clicked, it would still save some... Is there a way to cancel the whole process by clicking on the cancel button on the form?.
I just need some guidance as to how others have done this or were able to do this.
See if it helps:
private Thread td;
void Save()
{
//initialize the thread here
//...
td.Start();
//...
}
void Cancel()
{
if (td != null && td.IsAlive)
{
//warning canceling
//...
td.Abort();
}
}
I am developping an Outlook 2007 Add-In.
I have designed a Windows Form allowing to display operations the Add-In performs. The form is displayed modally.
In this form, I have 2 buttons, one to open an inspector on a mail item, the other to open an inspector on a contact item.
The "Show Mail" button behaves nicely, but the "Show Contact" always raises an exception saying that there is a dialog box open and I should close it before opening the contact inspector.
As the code for these 2 buttons is exactly the same, what would be the problem with the contact item inspector?
private void btnShowMail_Click(object sender, EventArgs e)
{
logEvent.MailItem.Display(true);
}
private void btnShowContact_Click(object sender, EventArgs e)
{
logEvent.ContactItem.Display(true);
}
If the problem is that my Form is open, I don't see how to work around.
Thanks for your help!
I have the same problem, I found that method ContactItem.Display is in colision with your form (If your form is a modal dialog)
Workaround:
If you are opening your form like:
myForm.ShowDialog();
change it to:
myForm.Show();
I know - thats not a good solution, but I didnt found better. :-(