我希望我的应用程序使用IFileOperation接口删除一堆文件。
我找到了这段代码,并将其作为类添加到我的项目中。
然后我这样使用它:
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();
}
我得到了这个错误:
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***DesktopProject NameClassesFileDir.cs:line 458
第458行是代码的这一部分:WindowInteropHelper wih = new WindowInteropHelper(ParentWindow);
知道为什么会发生这种事吗?
我认为您需要将;ParentWindow";您的";op";对象。执行((
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();