473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending Files to Recycle Bin



Hi all,
File.Delete(fileName) causes file to be deleted permanently. How to
send it to Recycle bin?

Please help,
Thanks in advance,

-Regards,
Dinesh
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
1 1270
Hi,

You have use the SHFileOperation API to do that.

The api declare

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As
Integer

End Function

The structure

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

The constants

Private Const FO_DELETE = &H3

Private Const FOF_ALLOWUNDO = &H40

And finally the same code.

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = FileName

.fFlags = FOF_ALLOWUNDO

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

Ken

--------------------------

"Dinesh Jain" <di*******@hotmail.com> wrote in message
news:Ot****************@TK2MSFTNGP12.phx.gbl...


Hi all,
File.Delete(fileName) causes file to be deleted permanently. How to
send it to Recycle bin?

Please help,
Thanks in advance,

-Regards,
Dinesh
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5817
by: Kerem Gümrükcü | last post by:
Hi, how can i get the pyhsical path to a recycle bin object. i am working with the FileSystemWatcher Object and i dont want to handle events inside the recycle bin, because the FSW Object...
12
39627
by: deko | last post by:
Is there a quick and dirty way to delete all files in a given directory? perhaps something like this: Set objFile = CreateObject("Scripting.FileSystemObject") objFile.DeleteFile "all files in...
1
6429
by: Frank Meng | last post by:
Hi. I wrote a program to get the directory of "Recycle Bin" with SHGetSpecialFolderLocation . It works for "Recent", "SendTo", etc. but it doesn't work for "Recycle Bin". At...
2
1645
by: avalain | last post by:
Hi, I am trying to delete files programmatically and put them in the Recycle Bin. I am using SHFileOperation and everything works fine, except when I try to delete files with more than 10...
4
5914
by: rob | last post by:
Does C# 2005 have an easy way to delete files to the recycle bin?
1
5936
by: Riky | last post by:
hi i have a windows application. I am select the folder or file name from the folderbrowserdialog box and to delete the folder or file i am calling the following code. Public Function...
2
4256
by: Kevin D. Smith | last post by:
I would like to move files and directories to the Recycle Bin on Windows from Python. I have found some older articles describing how to do this, but they require additional packages to be...
1
1365
by: Rich in Soquel | last post by:
We're running a FileSystemWatcher with Subdirectories included. Suppose that in the watch path, there's a folder called "Duh" containing files. If we delete the folder Duh, we get notified about...
2
5248
by: =?Utf-8?B?VVNBT3o=?= | last post by:
I am using Windows Vista Ultimate (x86). I accidently deleted my Desktop Recycle Bin. I restored it (Control Panel/Personalise/Change Desktop Icons). I clicked on the Recycle Bin (Full) icon...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.