- usingSystem.Runtime.InteropServices;
- privateconstintFO_DELETE=0x3;
- privateconstushortFOF_NOCONFIRMATION=0x10;
- privateconstushortFOF_ALLOWUNDO=0x40;
- [DllImport("shell32.dll")]
- privatestaticexternintSHFileOperation([In,Out]_SHFILEOPSTRUCTstr);
- [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
- publicclass_SHFILEOPSTRUCT
- {
- publicIntPtrhwnd;
- publicUInt32wFunc;
- publicstringpFrom;
- publicstringpTo;
- publicUInt16fFlags;
- publicInt32fAnyOperationsAborted;
- publicIntPtrhNameMappings;
- publicstringlpszProgressTitle;
- }
- publicstaticintDeleteToRecycleBin(stringpath)
- {
- _SHFILEOPSTRUCTpm=new_SHFILEOPSTRUCT();
- pm.wFunc=FO_DELETE;
- pm.pFrom=path+'/0';
- pm.pTo=null;
- pm.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
- returnSHFileOperation(pm);
- }
- privatevoidbutton1_Click(objectsender,EventArgse)
- {
- DeleteToRecycleBin(@"c:/temp/temp.txt");
- }
C#实现删除文件放入回收站
最新推荐文章于 2023-01-02 16:00:32 发布