[英]Issue in multiple files deletion using IFileOperation interface
I want my app to delete a bunch of files using the IFileOperation interface .我希望我的应用程序使用IFileOperation 接口删除一堆文件。
I found this code and I have added it as class into my project.我找到了这段代码,并将其作为 class 添加到我的项目中。
Then I use it like this:然后我像这样使用它:
public static void DeleteFiles(string data_path)
{
string[] files = Directory.GetFiles(data_path, "*.*", SearchOption.AllDirectories);
FileOperationG1 op = new FileOperationG1();
op.From = files;
op.Operation = FILEOP_CODES.FO_DELETE;
op.Flags = FILEOP_FLAGS.FOF_NOCONFIRMATION;
op.Flags = FILEOP_FLAGS.FOF_ALLOWUNDO;
op.Execute();
}
And I get this error:我得到这个错误:
System.ArgumentNullException: Value cannot be null.
Parameter name: window
at System.Windows.Interop.WindowInteropHelper..ctor(Window window)
at ***.Classes.FileDir.FileOperationG1.Execute() in C:\Users\***\Desktop\Project Name\Classes\FileDir.cs:line 458
At line 458 is this part of code: WindowInteropHelper wih = new WindowInteropHelper(ParentWindow);
第 458 行是这部分代码: WindowInteropHelper wih = new WindowInteropHelper(ParentWindow);
Any idea why is this happening?知道为什么会这样吗?
I think you will need to assign the "ParentWindow" property of your "op" object before running.Execute()我认为您需要在运行之前分配“op”object 的“ParentWindow”属性。执行()
FileOperationG1 op = new FileOperationG1();
// add this line VVVV
op.ParentWindow = ????? = "this object Window" // not real code
// fill in the ?????? ^^^^^^^
op.From = files;
op.Operation = FILEOP_CODES.FO_DELETE;
op.Flags = FILEOP_FLAGS.FOF_NOCONFIRMATION;
op.Flags = FILEOP_FLAGS.FOF_ALLOWUNDO;
op.Execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.