Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Um? How can I do this. :confused:

 

I have found all these great things in .Net that has made moving, deleting, copying files easier. All the special folders are easy to find but why is it hard to move or send a file to the recycle bin with or without the conferimation diolog.

 

Any thoughts

 

Thanks

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted

Update

 

Well I found this but it is just prompting for the delete.

 

Imports System.IO


   Private 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 Boolean
       Dim hNameMappings As Integer
       Dim lpszProgressTitle As String
   End Structure

   Private Const FO_DELETE As Short = &H3S
   Private Const FOF_ALLOWUNDO As Short = &H40S
   Private Const FOF_NOCONFIRMATION As Short = &H10S

   Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

  Public Function Recycle(ByRef sPath As String) As Integer
       Dim FileOp As SHFILEOPSTRUCT
       If Not File.Exists(sPath) Then
           MsgBox("Could not find " & sPath & "." & vbCrLf _
           & "Please verify the path.")
           Recycle = -1
           Exit Function
       End If
       With FileOp
           .wFunc = FO_DELETE
           .fFlags = FOF_ALLOWUNDO 'Or FOF_NOCONFIRMATION
           .pFrom = sPath & vbNullChar
           .pTo = vbNullChar
       End With
       Try
           SHFileOperation(FileOp)
       Catch ex As Exception
           MsgBox(ex.Message)
       End Try
       Recycle = 0
   End Function

 

Any Thoughts

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted
I don't know if there is a way to bypass the "Are you Sure?" dialog when deleting a file. You can turn the dialog off from the properties of the recycling bin. I don't know how to do it programmatically. Maybe a registry key?

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

I believe that you might be able to use this registry information to disable the Delete Conformation Dialog.

 

EDIT-This tweak just disables the recycling bin all together.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

After doing a bit more research I found this. I hope this helps you.

Turns off the recycle bin delete confirmation for all drives
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]
"ShellState"=hex:24,00,00,00,37,a8,01,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 01,00,00,00,0d,00,00,00,00,00,00,00,02,00,00,00

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Leaders
Posted

Generally, I would say that if the file you are deleting isn't a file that the user needs to know about then you should not worry about sending it to the recycle bin; just delete it. If it is a file that needs to be sent to the recycle bin in case the user will want to recover it, a message to the user confirming the delete might be appropriate so that the user knows what is going on.

 

I hope you aren't going do distribute a program that disables the "Are you sure" prompt for deleting the files. Even if it is only temporary, in the event of an error in your application this can cause very undesirable behavior on the end user's machine. I wouldn't wan't such software running on my PC, and depending on how it is programmed, the user might accidentally delete other files without even realizing it any time your program is running.

 

By the look of things, that registry setting may alter other settings as well. Unless you know for a fact that this is not the case, I recommend doing more research on that registry key.

[sIGPIC]e[/sIGPIC]
Posted

The Goal

 

Generally, I would say that if the file you are deleting isn't a file that the user needs to know about then you should not worry about sending it to the recycle bin; just delete it. If it is a file that needs to be sent to the recycle bin in case the user will want to recover it, a message to the user confirming the delete might be appropriate so that the user knows what is going on.

 

I hope you aren't going do distribute a program that disables the "Are you sure" prompt for deleting the files. Even if it is only temporary, in the event of an error in your application this can cause very undesirable behavior on the end user's machine. I wouldn't wan't such software running on my PC, and depending on how it is programmed, the user might accidentally delete other files without even realizing it any time your program is running.

 

By the look of things, that registry setting may alter other settings as well. Unless you know for a fact that this is not the case, I recommend doing more research on that registry key.

 

First off thanks for the replys! :)

 

Basicly I am writing a program to automate the archiving of files. I have a folder I have to mannually archive everyweek. Leave the newest two weeks move the third to an archive folder. In the archive folder delete the oldest weeks worth of files. I wanted to have the option of just sending the files to the recycle bin built into the application.

 

Now with the code in my earlier post I can supress the confirmation prompt (app only) but it deletes the files and the prompt that is displayed when it is not supressed is the one when you hold down the "Shift" key and hit delete while a file is selected. The option of sending the file to the recycle bin doesn't come up.

 

I have the whole thing done other than the option for the recycle bin.

 

Any other thoughts, I do think this wilol help more people that just me.

 

Thanks for all the input from everyone.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted
http://www.codeproject.com/shell/recyclebin.asp

 

c++ , but good explanations of what he's doing.

 

I think I might have to read this a few times, I don't know C++. So it's losing me a little. I also don't have C++ so the source files are no good to me. I do think the artical is good I just need to get some more knowledge before I'm able to under stand it.

 

Does any one know of a VB.Net example?

 

Thanks for the help

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

  • Leaders
Posted
Just a thought: If you want the files to be recoverable, why not simply remove them to your [application's] own backup folder instead of cluttering the recycle bin?
[sIGPIC]e[/sIGPIC]
Posted

Thanks

 

Just a thought: If you want the files to be recoverable' date=' why not simply remove them to your [application's'] own backup folder instead of cluttering the recycle bin?

 

I think that might be my best option for right now. Refering to the post to above this one. Those flags with the code above still bypassed the recycle bin. :(

 

Thanks for all you help.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...