请原谅我是编码新手。我可以按照我想要的方式进行拖放,但我需要知道的是如何从列表框中拉出并在用户将文件放入列表框中后将其作为 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);
}
我收到一条错误消息,提示“抱歉,出了点问题,请重试”。我认为将列表框中的所有项目都转换为文本可能有效,但有更好的方法吗?