【问题标题】:Add-in for Outlook in C# (Saving the Attachment and adding a url reference to the saved file path as attachment)C# 中的 Outlook 加载项(保存附件并将对已保存文件路径的 url 引用添加为附件)
【发布时间】:2013-03-05 11:14:52
【问题描述】:

我正在使用 VS 2010 和 Dot Net Framework 2.0。我在 Extensibility->Shared Add-ins for Outlook 中创建了一个项目。 我想在我的硬盘中保存一个文件(任何文件),删除该附件并将该文件的路径添加为附件,如果用户单击此文件,它应该在我的硬盘中打开该保存的文件。 我可以保存文件,删除附件,但我无法将文件的路径保存为附件 这是为保存和删除而编写的代码

                if (item is Outlook.MailItem)
                {
                    Outlook.MailItem mi = (Outlook.MailItem)item;
                    if (mi != null)
                    {                            
                        for (int i = 1; i <= mi.Attachments.Count; i++)
                        {
                            string FilePath = @"" + Settings.Default.browseFolderPath + @"\" +
                                mi.Attachments[i].FileName;
                            mi.Attachments[i].SaveAsFile(FilePath);                                
                            mi.Attachments.Remove(i);                                
                            mi.Attachments.Add(creatingLinkToFile(FilePath), Type.Missing, i, Type.Missing);
                            mi.Save();
                        }                           
                    }
                } 


    private string creatingLinkToFile(string url)
    {
        string lnkPath =@"C:\shortcut.lnk";
        WshShellClass shell = new WshShellClass();           
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(lnkPath);
        shortcut.TargetPath = @"" + url;
        shortcut.Description = "Trial";
        shortcut.Save();
        return lnkPath;
    }

请任何人给我和想法,因为我使用了 lnk 文件,但这对前景不起作用。

【问题讨论】:

  • 你不应该将它创建为 c:\shortcut.lnk,你应该在用户的临时目录中创建它。

标签: c# winforms com outlook-addin outlook-2007


【解决方案1】:

您可以使用具有 olByReference 的枚举 OlAttachmentType 如下图所示,你就完成了。

mi.Attachments.Add(""+[path of file to Attach Reference], OlAttachmentType.olByReference, i, Type.Missing);

【讨论】:

    猜你喜欢
    • 2022-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2023-02-02
    • 1970-01-01
    相关资源
    最近更新 更多