Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8764779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:07:07+00:00 2026-06-13T16:07:07+00:00

I am developing an add-in for outlook 2010. Basically, I have a button on

  • 0

I am developing an add-in for outlook 2010.
Basically, I have a button on my ribbon that takes the selected email, and saves it to a text file. If the email contains a certain subject then the save is done automatically to a hard coded file path. If not, a windows form is opened asking the user to enter a filepath.

When the user has selected a path, and clicked ‘OK’ the save takes place and then the form closes… but then it re-opens… it seems to be creating a new instance of it or something… if I click ‘Cancel’ or ‘X’ it closes, but I can’t see why it’s not closing properly the first time.

Below is my code

//This is myRibbon.cs
private void btn_SaveFile_Click(object sender, RibbonControlEventArgs e) 
{
   //other code
   if (subject = "xyz") 
   {
      //other code
      textFile.Save();
   }
   else
   {
      MyPopup popup = new MyPopup();
      popup.ShowDialog();
   }
}

//This is MyPopup.cs
private void btnOK_Click(object sender, EventArgs e) 
{
   var filePath = txtFilePath.Text;
   if (!string.IsNullOrWhiteSpace(filePath)) 
   { 
       SaveEmailToText(filePath); 
      this.Close(); 
   }
   else 
   { //show message box with error }
   this.Close(); 
}

private static void SaveEmailToText(string filePath) 
{
    //other code
    textFile.Save();
}

I have simplified this quite a bit so its easier to read.
Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:07:08+00:00Added an answer on June 13, 2026 at 4:07 pm
    • Consider to use OpenFileDialog instead of your popup form
    • Use your popup (or file dialog) only for getting file name
    • Keep email saving code in one place (otherwise you will have duplicated code)
    • Verify DialogResult of dialog form, before processing further
    • Forms are disposable – using statement will dispose them automatically
    • Do not close dialog form – set it’s DialogResult property instead

    Here is refactored code:

    private void btn_SaveFile_Click(object sender, RibbonControlEventArgs e) 
    {
       string filePath = defaultPath;
    
       if (subject != "xyz") 
       {
          using(MyPopup popup = new MyPopup())
          {
             // user can close popup - handle this case
             if (popup.ShowDialog() != DialogResult.OK)
                 return;
             filePath = popup.FilePath;
          }
       }       
    
       SaveEmailToText(filePath);
    }
    
    private void SaveEmailToText(string filePath) 
    {
       //other code
       textFile.Save();
    }
    

    And your popup, which should be replaced with OpenFileDialog:

    private void btnOK_Click(object sender, EventArgs e) 
    {
        if (string.IsNullOrWhiteSpace(FilePath))
        { 
            //show message box with error
            DialogResult = DialogResult.Cancel;
            return;
        }
    
        // you can assign default dialog result to btnOK in designer
        DialogResult = DialogResult.OK;
    }
    
    public string FilePath
    {
        get { return txtFilePath.Text; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an outlook 2010 add-in in c#/.net. I have some items that I
I am developing add-in for Outlook 2010. I have to get all rules and
I'm developing an Outlook 2010 Add-In in C# which adds a docked Custom Task
I am developing an Outlook Add-in that is using Outlook contacts from local machine
I have been tasked with developing a Firefox add-on that is capable of registering
I am developing a VSTO 2010 Office 2007 Outlook Add-In deployed from Click-Once. On
I'm developing an add on to a system I have that will allow my
I am currently developing an Outlook add in that automatically creates a signature in
Currently developing an Outlook add-in with Add-in Express, I have to revert to some
I'm developing an Add In for Outlook (2007 and 2010) using .NET4 to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.