在C#中如何将文件放入回收站。
来源:互联网 发布:网络语言暴力论文总结 编辑:程序博客网 时间:2024/04/28 11:46
当我的系统可以提供文件操作的时候,我总是尽可能小心对付每一次删除请求,因为,也许用户有可能会在下一分钟因为这次的误操作而后悔不已。
///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);
///implementation
public 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;
}
- 在C#中如何将文件放入回收站。
- 如何使用win32 API实现将文件放入回收站
- VC实现将文件放入回收站
- c# 如何将文件删除到回收站(文件操作)
- 如何将自己的文件作为资源文件放入VC工程中?如何在运行时,从EXE文件中提取(释放)出这个文件?
- 如何将so文件放入Android项目
- c# 如何将图片信息从数据库中读取出来放入pictureBox1中:
- root后adb shell默认不是root用户时,如何将文件放入手机系统中
- root后adb shell默认不是root用户时,如何将文件放入手机系统中
- root后adb shell默认不是root用户时,如何将文件放入手机系统中
- 如何在.NET2005中,放入Addins(插件)
- 如何在SharePoint中隐藏回收站
- C# WinForm中如何将文件保存在文件夹中或如何新建文件夹来保存
- KeilC如何通过linker将文件放入指定存储地址
- 如何将Linux rm命令删除的文件放入垃圾箱
- C# 将picturebox放入panel中,增加滚动条
- 将数据从文件中读出来放入list中
- 如何将exec执行结果放入变量中
- 王磊《出门人》
- C#异步调用
- Visual C# 2005 Express Edition Beta的第一天使用
- 跟着风走
- 通过Web服务外置XML,将Web服务用作数据源,Web服务传递的内容是XML,将由Web服务返回的XML文档,以便可以将它加载到客户机上的XML分析器。
- 在C#中如何将文件放入回收站。
- 在C#中使用属性控件添加属性窗口
- .net 2.0
- Mono l.0正式发布了
- DOTNET VWD 2005 先睹为快
- 奇怪。为什么我的摘要没有格式呢
- 十个必备的.NET开发小工具(2):Regulator
- JAVA学习-之-log4j配置文件
- 眼见不为实——经典幻觉图形(已更新)