Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5928049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:14:53+00:00 2026-05-22T14:14:53+00:00

Possible Duplicate: How do I restore a file from the recycle bin using C#?

  • 0

Possible Duplicate:
How do I restore a file from the recycle bin using C#?

Someone knows how to restore files from recycle bin using C# with the Windows API?.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:14:54+00:00Added an answer on May 22, 2026 at 2:14 pm

    This link can help you

    using System;
    using System.Collections;
    using System.Windows.Forms;
    using System.IO;
    using Shell32; //Reference Microsoft Shell Controls And Automation on the COM tab.
    using System.Runtime.InteropServices;
    using Microsoft.VisualBasic.FileIO;
    namespace RecyclerCS
    {
      public partial class Form1 : Form
      {
        public Form1() {
          InitializeComponent();
        }
        private Shell Shl;
        private const long ssfBITBUCKET = 10;
        private const int recycleNAME = 0;
        private const int recyclePATH = 1;
    
        private void button1_Click(object sender, System.EventArgs e) {
          string S = "This is text in the file to be restored from the Recycle Bin.";
          string FileName = "C:\\Temp\\Text.txt";
          File.WriteAllText(FileName, S);
          Delete(FileName);
          MessageBox.Show(FileName + " has been moved to the Recycle Bin.");
          if (Restore(FileName))
            MessageBox.Show(FileName + " has been restored");
          else
            MessageBox.Show("Error");
          Marshal.FinalReleaseComObject(Shl);
        }
        private void Delete(string Item) {
          FileSystem.DeleteFile(Item, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
          //Gives the most control of dialogs.
        }
        private bool Restore(string Item) {
          Shl = new Shell();
          Folder Recycler = Shl.NameSpace(10);
          for (int i = 0; i < Recycler.Items().Count; i++) {
            FolderItem FI = Recycler.Items().Item(i);
            string FileName = Recycler.GetDetailsOf(FI, 0);
            if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path);
            //Necessary for systems with hidden file extensions.
            string FilePath = Recycler.GetDetailsOf(FI, 1);
            if (Item == Path.Combine(FilePath, FileName)) {
              DoVerb(FI, "ESTORE");
              return true;
            }
          }
          return false;
        }
        private bool DoVerb(FolderItem Item, string Verb) {
          foreach (FolderItemVerb FIVerb in Item.Verbs()) {
            if (FIVerb.Name.ToUpper().Contains(Verb.ToUpper())) {
              FIVerb.DoIt();
              return true;
            }
          }
          return false;
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I restore a file from the recycle bin using C#?
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Restore a deleted file in a Git repo How do I restore
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Restore a deleted file in a Git repo I have two branches
Possible Duplicate: git - removing a file from source control (but not from the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: Parsing text in C Say I have written to a text file
Possible Duplicate: Resetting a multi-stage form with jQuery Once the form submitted, response from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.