c# - 没有源码目录怎么拖放文件?

标签 c# drag-and-drop directory attachment

我有一个小程序,当用户将文件拖到面板中时,它基本上将文件移动到特定文件夹中。这适用于任何具有目录路径的东西。但是,如果我将附件从 Outlook 拖到面板中,软件就会崩溃。

(理论上的修复)将文件的名称放入面板,应用 File.Move(attachmentName, temporaryDirectory) 但是,这看起来很乱。

private void panel2_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.All;
}

public void panel2_DragDrop(object sender, DragEventArgs e)
{
    string destination = @"\\MAIL\DocupaceScans\fsnrep\FSNbp";

    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
    foreach (string file in files)

    File.Copy(file, destination + "\\" + Path.GetFileName(file));

    MessageBox.Show("Thanks!");
}

最佳答案

您需要获取 outlook 安全临时文件夹的位置,该文​​件夹在 Windows 7 及更高版本中位于此位置,

"C:\Users\ < user > \AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\"

要实现它,请使用一个 try catch block 和一个 if else 语句来说明它应该从哪里来,这样您就可以捕获您的异常,并相应地处理错误。

关于c# - 没有源码目录怎么拖放文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32275472/

相关文章:

时间:2019-03-17 标签:c#error: Use of unassigned local variable (context visual studio T4 ENGINE)

c# - 在 WPF 中使用枚举作为依赖属性

javascript - html5 : is there a way to prevent children interfering with drag events

javascript - 当我拖动时,dragend、dragenter 和 dragleave 会立即发射

bash - 使用文件系统功能进行Bash编程

c# - 在 .net 中,我应该使用什么类来轻松处理数据库中的数据(不包括 Entity Framework 或 LINQ)

c# - 在 C# 中验证一个字符串是否只包含字母

java - 拖放方法不会触发

c++ - 如何使用 Windows API C++ 更改已创建的文件夹/目录安全权限

java - 检查目录是否可以打开并列出其文件