By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

Delete files to recycle bin

P: n/a
rob
Does C# 2005 have an easy way to delete files to the recycle bin?
Sep 30 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Rob,
Does C# 2005 have an easy way to delete files to the recycle bin?
The .NET Framework doesn't have built-in support for this, but you can call
the Shell Win32 API function SHFileOperation along with the flag
FOF_ALLOWUNDO.

Here's a C# example, though I haven't tested this:
http://www.personalmicrocosms.com/Pa...aspx?c=19&t=22

Another example from PInvoke.net, which is useful if you want to call Win32
APIs from managed code:
http://www.pinvoke.net/default.aspx/...Operation.html

And finally some text from the documentation of SHFileOperation from MSDN:
http://msdn.microsoft.com/library/de...eoperation.asp

"When used to delete a file, SHFileOperation permanently deletes the file
unless you set the FOF_ALLOWUNDO flag in the fFlags member of the
SHFILEOPSTRUCT structure pointed to by lpFileOp. Setting that flag sends the
file to the Recycle Bin. If you want to delete a file and guarantee that it
is not placed in the Recycle Bin, use DeleteFile."

Hope this solves your problem.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi
http://www.saunalahti.fi/janij/
Sep 30 '06 #2

P: n/a
Rob
On Sat, 30 Sep 2006 09:01:40 +0300, "Jani Järvinen [MVP]"
<ja***@removethis.dystopia.fiwrote:
>Hi Rob,
>Does C# 2005 have an easy way to delete files to the recycle bin?

The .NET Framework doesn't have built-in support for this, but you can call
the Shell Win32 API function SHFileOperation along with the flag
FOF_ALLOWUNDO.

Here's a C# example, though I haven't tested this:
http://www.personalmicrocosms.com/Pa...aspx?c=19&t=22
Terrific, Jani. I think that fills in the blanks. I suspected that I'd
have to go with Pinvoke. My first run at SHFileOp didn't work, but I
think you've clarified the missing flag.

I'm surprised that the .NET 2005 library still has holes in some
pretty fundamental operations. This seems like it would have been easy
for MS to wrap in the C# library.

Thanks again
Sep 30 '06 #3

P: n/a
Can't find anything easy for you yet but this:
http://www.codeguru.com/cpp/com-tech...cle.php/c1341/

chanmm

"Rob" <Ro*@nospam.comwrote in message
news:5k********************************@4ax.com...
On Sat, 30 Sep 2006 09:01:40 +0300, "Jani Järvinen [MVP]"
<ja***@removethis.dystopia.fiwrote:
>>Hi Rob,
>>Does C# 2005 have an easy way to delete files to the recycle bin?

The .NET Framework doesn't have built-in support for this, but you can
call
the Shell Win32 API function SHFileOperation along with the flag
FOF_ALLOWUNDO.

Here's a C# example, though I haven't tested this:
http://www.personalmicrocosms.com/Pa...aspx?c=19&t=22

Terrific, Jani. I think that fills in the blanks. I suspected that I'd
have to go with Pinvoke. My first run at SHFileOp didn't work, but I
think you've clarified the missing flag.

I'm surprised that the .NET 2005 library still has holes in some
pretty fundamental operations. This seems like it would have been easy
for MS to wrap in the C# library.

Thanks again

Oct 1 '06 #4

P: n/a
One more like to try to you need to convert to C# perhaps:
http://www.developerfusion.co.uk/show/5673/

chanmm

"Rob" <Ro*@nospam.comwrote in message
news:5k********************************@4ax.com...
On Sat, 30 Sep 2006 09:01:40 +0300, "Jani Järvinen [MVP]"
<ja***@removethis.dystopia.fiwrote:
>>Hi Rob,
>>Does C# 2005 have an easy way to delete files to the recycle bin?

The .NET Framework doesn't have built-in support for this, but you can
call
the Shell Win32 API function SHFileOperation along with the flag
FOF_ALLOWUNDO.

Here's a C# example, though I haven't tested this:
http://www.personalmicrocosms.com/Pa...aspx?c=19&t=22

Terrific, Jani. I think that fills in the blanks. I suspected that I'd
have to go with Pinvoke. My first run at SHFileOp didn't work, but I
think you've clarified the missing flag.

I'm surprised that the .NET 2005 library still has holes in some
pretty fundamental operations. This seems like it would have been easy
for MS to wrap in the C# library.

Thanks again

Oct 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.