//For complete examples and data files, please go to https://github.com/groupdocsmetadata/GroupDocs_Metadata_NET
namespace GroupDocs.Metadata.OutlookAddin
{
[ComVisible(true)]
public class Ribbon1 : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
public Ribbon1()
{
}
public void AttachFileUsingGroupDocsMetadata(Office.IRibbonControl control)
{
try
{
//Create open file dialog...
OpenFileDialog ofdAttachFile = new OpenFileDialog();
//Initialize open file dialog...
InitializeOpenFileDialog(ofdAttachFile);
DialogResult result = ofdAttachFile.ShowDialog();
string strFileName = string.Empty;
string message = string.Empty;
if (result == DialogResult.OK)
{
MessageBox.Show("Cleaning of multiple files may take time. Please be patient.");
foreach (string fileName in ofdAttachFile.FileNames)
{
//Get file name...
strFileName = fileName;
try
{
//Clean metadata of file...
message = Common.CleanDocument(strFileName);
}
catch (Exception exp)
{
MessageBox.Show("Exception in cleaning file: " + exp.Message);
}
try
{
//Get mail item of Outlook...
Outlook.MailItem mail = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;
//Attach file with mail
mail.Attachments.Add(strFileName, Outlook.OlAttachmentType.olByValue, 1, strFileName);
//Display mail...
mail.Display();
}
catch (Exception exp)
{
MessageBox.Show("Exception in attachment: " + exp.Message);
}
}
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
protected void InitializeOpenFileDialog(OpenFileDialog ofd)
{
try
{
//Set filters...
ofd.Filter = "Documents (*.XLS;*.XLSX;*.DOC;*.DOCX;*.PPT;*.PPTX;*.PDF)|*.XLS;*.XLSX;*.PPT;*.PPTX;*.DOC;*.DOCX;*.PDF|" + "Images (*.PNG;*.JPG;*.JPEG;*.GIF)|*.BMP;*.JPG;*.GIF|" + "All files (*.*)|*.*";
//Allow the user to select multiple files...
ofd.Multiselect = true;
//Set title of dialog...
ofd.Title = "Select file(s)";
}
catch
{ }
}
public Bitmap GetCustomImage(Office.IRibbonControl control)
{
//Set icon for the add-in
return Properties.Resources.icon;
}
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
{
return GetResourceText("GroupDocs.Metadata.OutlookAddin.Ribbon1.xml");
}
#endregion
#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}
#endregion
#region Helpers
private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourceNames.Length; ++i)
{
if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
{
using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
{
if (resourceReader != null)
{
return resourceReader.ReadToEnd();
}
}
}
}
return null;
}
#endregion
}
}