【问题标题】:C# WPF Attachments from listbox to outlook attachment从列表框到 Outlook 附件的 C# WPF 附件
【发布时间】:2018-06-20 20:02:27
【问题描述】:

请原谅我是编码新手。我可以按照我想要的方式进行拖放,但我需要知道的是如何从列表框中拉出并在用户将文件放入列表框中后将其作为 Outlook 的附件发送。这就是我到目前为止所拥有的。

private void AttachmentBox_Drop(object sender, DragEventArgs e)
        {
            string[] DropPath = e.Data.GetData(DataFormats.FileDrop, true) as string[];
            foreach (string dropfilepath in DropPath)
            {
                ListBoxItem listboxitem = new ListBoxItem();
                if (System.IO.Path.GetExtension(dropfilepath).Contains("."))
                {
                    listboxitem.Content = System.IO.Path.GetFullPath(dropfilepath);
                    listboxitem.ToolTip = DropPath;
                    AttachmentBox.Items.Add(listboxitem);
                }
            }
        }

现在这似乎是我卡住的地方。它不会附加列表框中的任何内容。

 //Add Attachment from Listbox
                    if (AttachmentBox.Items != null)
                {
                    Outlook.Attachment oAttach = oMsg.Attachments.Add(AttachmentBox.Items);
                }

我收到一条错误消息,提示“抱歉,出了点问题,请重试”。我认为将列表框中的所有项目都转换为文本可能有效,但有更好的方法吗?

【问题讨论】:

  • 您的假设是正确的,您告诉它添加字符串列表,而不是实际文件。

标签: c# wpf outlook listbox


【解决方案1】:

知道了!谢谢我!

foreach (string fileLoc in myAttachmentPaths)
                    {
                        //attach the file
                        Outlook.Attachment oAttach = oMsg.Attachments.Add(fileLoc);
                    }                       

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多