внешний вид addin attachment.savefileas - PullRequest
0 голосов
/ 27 апреля 2018

Вложение найдено, но файл не сохраняется. Кажется, что во время отладки оно успешно сохраняется, но файл не находится в тестовом пути.

    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);
        }

    }
}

1 Ответ

0 голосов
/ 27 апреля 2018

Необходимо указать полный путь и имя файла для метода SaveAsFile, а не просто путь к папке:

string filename = Path.Combine(archivePath , vendFile.FileName);
vendFile.SaveAsFile(filename);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...