FILE.DELETE(PATH)虽然可以删除文件,但是不会把删除的文件放到回收站中.请问怎么才可以把删除文件放到回收站中.谢谢
解决方案 »
- c# datagridview 中的value值为空时如何判断??
- 将结构转成bytes,英文可以,中文就不报错,应该如何解决
- Socket打包解包的问题
- 如何把数据库里的nuber型的数字在datagrid上用八进制显示出来?
- Visual Source Safe 6.0C
- 为什么&&在c# 2005编译器里被看做是是运算符?
- 为什么treeview1.SelectedNode.Parent.Nodes.Add(temp);不能使??
- 如何请求ftp://这样得internet文件
- 【悬赏-加分结贴】新手请教C# 调用VFP OLEDB API的异常
- 求助:C#调用Zlib库实现字符串压缩问题
- 新手求助
- 怎样修改哈希表的健值
///SHFILEOPSTRUCT definition [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd; // Window handle to the dialog box to display information about the
// status of the file operation.
public UInt32 wFunc; // Value that indicates which operation to perform.
public IntPtr pFrom; // Address of a buffer to specify one or more source file names.
// These names must be fully qualified paths. Standard Microsoft?
// MS-DOS?wild cards, such as "*", are permitted in the file-name
// position. Although this member is declared as a null-terminated
// string, it is used as a buffer to hold multiple file names. Each
// file name must be terminated by a single NULL character. An
// additional NULL character must be appended to the end of the
// final name to indicate the end of pFrom.
public IntPtr pTo; // Address of a buffer to contain the name of the destination file or
// directory. This parameter must be set to NULL if it is not used.
// Like pFrom, the pTo member is also a double-null terminated
// string and is handled in much the same way.
public UInt16 fFlags; // Flags that control the file operation.
public Int32 fAnyOperationsAborted; // Value that receives TRUE if the user aborted any file operations
// before they were completed, or FALSE otherwise.
public IntPtr hNameMappings; // A handle to a name mapping object containing the old and new
// names of the renamed files. This member is used only if the
// fFlags member includes the FOF_WANTMAPPINGHANDLE flag.
[MarshalAs(UnmanagedType.LPWStr)]
public String lpszProgressTitle; // Address of a string to use as the title of a progress dialog box.
// This member is used only if fFlags includes the
// FOF_SIMPLEPROGRESS flag.
} ///API declaration, using it you can copies, moves, renames, or deletes a file system object.
[DllImport("shell32.dll" , CharSet = CharSet.Unicode)]
public static extern Int32 SHFileOperation(
ref SHFILEOPSTRUCT lpFileOp);///implementationpublic bool DeleteFiles(string[] files){ SHFILEOPSTRUCT FileOpStruct = new SHFILEOPSTRUCT();
FileOpStruct.hwnd = OwnerWindow;
FileOpStruct.wFunc = (uint)Operation; String multiSource = StringArrayToMultiString(SourceFiles);
String multiDest = StringArrayToMultiString(DestFiles);
FileOpStruct.pFrom = Marshal.StringToHGlobalUni(multiSource);
FileOpStruct.pTo = Marshal.StringToHGlobalUni(multiDest);
FileOpStruct.fFlags = (ushort)OperationFlags;
FileOpStruct.lpszProgressTitle = ProgressTitle;
FileOpStruct.fAnyOperationsAborted = 0;
FileOpStruct.hNameMappings = IntPtr.Zero; int RetVal;
RetVal = ShellApi.SHFileOperation(ref FileOpStruct);} private String StringArrayToMultiString(String[] stringArray)
{
String multiString = ""; if (stringArray == null)
return ""; for (int i=0 ; i<stringArray.Length ; i++)
multiString += stringArray[i] + '\0';
multiString += '\0';
return multiString;
}
private const int FO_DELETE = 0x3;
private const ushort FOF_NOCONFIRMATION = 0x10;
private const ushort FOF_ALLOWUNDO = 0x40; [DllImport("shell32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
private static extern int SHFileOperation([In,Out] _SHFILEOPSTRUCT str); [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public class _SHFILEOPSTRUCT
{
public IntPtr hwnd;
public UInt32 wFunc;
public string pFrom;
public string pTo;
public UInt16 fFlags;
public Int32 fAnyOperationsAborted;
public IntPtr hNameMappings;
public string lpszProgressTitle;
} public static int Delete(string path)
{
_SHFILEOPSTRUCT pm = new _SHFILEOPSTRUCT();
pm.wFunc = FO_DELETE;
pm.pFrom = path + '\0';
pm.pTo = null;
pm.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
return SHFileOperation(pm);
} 调用这个delete方法
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(String, UIOption, RecycleOption):注意:此方法在 .NET Framework 2.0 版中是新增的。 删除文件。 命名空间:Microsoft.VisualBasic.FileIO
程序集:Microsoft.VisualBasic(在 microsoft.visualbasic.dll 中)
参数
file
String。要删除的文件的名称和路径。必选。 showUI
UIOption。是否对操作进度进行可视跟踪。默认为 UIOption.OnlyErrorDialogs。必选。 recycle
RecycleOption。删除的文件是否应发送到“回收站”。默认为 RecycleOption.DeletePermanently。必选。