C#从列表框到outlook附件的WPF附件
请原谅,我对编码还不熟悉。我有拖放工作的方式,我想要的,但我需要知道的是如何从列表框中拉,并让它作为一个附件与outlook发送后,用户在列表框中删除文件。这就是我目前所拥有的C#从列表框到outlook附件的WPF附件,c#,wpf,outlook,listbox,C#,Wpf,Outlook,Listbox,请原谅,我对编码还不熟悉。我有拖放工作的方式,我想要的,但我需要知道的是如何从列表框中拉,并让它作为一个附件与outlook发送后,用户在列表框中删除文件。这就是我目前所拥有的 private void AttachmentBox_Drop(object sender, DragEventArgs e) { string[] DropPath = e.Data.GetData(DataFormats.FileDrop, true) as string[];
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);
}
我收到一个错误,说“对不起,出了问题,请再试一次”。我认为将列表框中的所有项目转换为文本可能有效,但有更好的方法吗 明白了!谢谢我
foreach (string fileLoc in myAttachmentPaths)
{
//attach the file
Outlook.Attachment oAttach = oMsg.Attachments.Add(fileLoc);
}
您的假设是正确的,您告诉它添加字符串列表,而不是实际的文件。