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