none
C# Split Button Visual Studio 2015 RRS feed

  • Question

  • Hey,

    i´m writing an Add-In and use a Split Button from the Toolbox on the Ribbondesigner. I tried a lot of things but i´m not enable to fill the Splitbutton(arrow) with Items oder Strings or anything. 

    Thats my Code for the upperpart of the Button. Works fine.

    using System;
    using Microsoft.Office.Tools.Ribbon;
    using System.Text.RegularExpressions;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using System.IO;
    using System.Windows.Forms;
    
    namespace NewFinal2
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void splitButton1_Click(object sender, RibbonControlEventArgs e)
            {
                Outlook.Application myApplication = Globals.ThisAddIn.Application;
                Outlook.Explorer myActiveExplorer = (Outlook.Explorer)myApplication.ActiveExplorer();
                Outlook.Selection selection = myActiveExplorer.Selection;
                System.Windows.Forms.FolderBrowserDialog objDialog = new FolderBrowserDialog();
                string userName = System.Environment.UserName;
    
                
    
    
    
                string path = "C:\\Users\\" + userName + "\\AppData\\Roaming\\Microsoft\\AddIns\\FilePlanPath.txt";
                if (!File.Exists(path))
                {
                    objDialog.Description = "FilePlan Ordner";
                    objDialog.SelectedPath = @"C:\";       // Vorgabe Pfad (und danach der gewählte Pfad)
                    objDialog.ShowDialog();
                    File.WriteAllText(path, objDialog.SelectedPath);
                }
    
                string savePath = File.ReadAllText(@"C:\Users\sgeuking\AppData\Roaming\Microsoft\AddIns\FilePlanPath.txt");
                savePath += @"\";
                string sSubject = string.Empty;
                string sName;
    
                for (int iLoop = 1; iLoop <= selection.Count; iLoop++)
                {
                    Object selObject = myActiveExplorer.Selection[iLoop];
                    if (selObject != null && selObject is Outlook.MailItem)
                    {
                        Outlook.MailItem mail = (Outlook.MailItem)selection[iLoop];
                        sName = string.Format("{0:yyyyMMddHHmmss_tt}", mail.ReceivedTime);
                        sSubject = mail.Subject;
                        sName += replace(sSubject);
                        mail.SaveAs(savePath + sName + ".msg", Outlook.OlSaveAsType.olMSG);
                    }
    
                }
            }
    
            private string replace(string sName)
            {
                sName = Regex.Replace(sName, "[^0-9A-Za-zäöüÄÖÜ ,]", "_");
                sName = sName.Replace(" ", "_");
                return sName;
            }
        }
    }

    I hope someone can help me.

    greetings

    • Moved by Kristin Xie Monday, November 2, 2015 2:12 AM move to appropriate forum
    Friday, October 30, 2015 2:35 PM

Answers

All replies