Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# outlook加载项附件.savefileas_C#_Outlook Addin - Fatal编程技术网

C# outlook加载项附件.savefileas

C# outlook加载项附件.savefileas,c#,outlook-addin,C#,Outlook Addin,已找到附件,但未保存文件。调试时,文件似乎已成功保存,但该文件不在测试路径中 private void button1_Click(object sender, RibbonControlEventArgs e) { Outlook.Inspector currInspector = null; Outlook.MailItem mail = null; Outlook.Attachments attachments = null;

已找到附件,但未保存文件。调试时,文件似乎已成功保存,但该文件不在测试路径中

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

    }
}
private void按钮1\u单击(对象发送者,RibbonControlEventArgs e)
{
Outlook.Inspector currInspector=null;
Outlook.MailItem mail=null;
Outlook.Attachments=null;
//工作时更改为生产路径,下面是测试路径
字符串路径=@“H:\Customer Service”;
字符串archivePath=@“H:\Customer Service\Helpers”;
尝试
{
currInspector=Globals.ThisAddIn.Application.ActiveWindow();
mail=(Outlook.MailItem)currInspector.CurrentItem;
附件=mail.attachments;

对于(int i=1;i您需要为
SaveAsFile
方法指定完全限定的路径和文件名,而不仅仅是文件夹路径:

string filename = Path.Combine(archivePath , vendFile.FileName);
vendFile.SaveAsFile(filename);