简体   繁体   English

如果没有源目录,如何拖放文件?

[英]How can I drag and drop files when there is no source directory?

I have a little program that essentially moved files into a specific folder when the user drags the file into a panel. 当用户将文件拖放到面板中时,我有一个基本上将文件移动到特定文件夹的程序。 This works for anything that has a directory path. 这适用于具有目录路径的任何内容。 However, the software crashes if I drag an attachment from outlook into the panel. 但是,如果我将附件从outlook拖到面板中,软件会崩溃。

(theoretical fix) Take the name of the file being placed into the panel, apply File.Move(attachmentName, temporaryDirectory) however, this seems messy. (理论修复)获取放置在面板中的文件的名称,应用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!");
}

You need to get the location of the outlook secure temp folder, which is at this location from Windows 7 and above, 您需要获取outlook安全临时文件夹的位置,该文​​件夹位于Windows 7及更高版本的此位置,

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

to implement it, use a try catch block and an if else statement to say where its should be coming from, so that you can catch your exception, and handle the error accordingly. 要实现它,请使用try catch块和if else语句来说明它应该来自何处,以便您可以捕获异常,并相应地处理错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM