Вложение найдено, но файл не сохраняется. Кажется, что во время отладки оно успешно сохраняется, но файл не находится в тестовом пути.
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Inspector currInspector = null;
Outlook.MailItem mail = null;
Outlook.Attachments attachments = null;
//change to production paths when working, below are test paths
string path = @"H:\Customer Service";
string archivePath = @"H:\Customer Service\Helpers";
try
{
currInspector = Globals.ThisAddIn.Application.ActiveWindow();
mail = (Outlook.MailItem)currInspector.CurrentItem;
attachments = mail.Attachments;
for (int i = 1; i <= attachments.Count; i++)
{
Outlook.Attachment vendFile = attachments[i];
//save original in archive folder
vendFile.SaveAsFile(archivePath + vendFile);
//begin document modification and save to path
//StreamWriter streamWriter = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.ReadWrite));
//dispose of object
Marshal.ReleaseComObject(vendFile);
}
}
catch
{
MessageBox.Show("Unable to retrieve attachment");
}
finally
{
if (attachments != null) Marshal.ReleaseComObject(attachments);
if (mail != null) Marshal.ReleaseComObject(mail);
if (currInspector != null) Marshal.ReleaseComObject(currInspector);
}
}
}