C # Delete files and folders to the Recycle Bin

Source: Internet
Author: User

From: http://www.soaspx.com/dotnet/csharp/csharp_20120926_9646.html

If you use C # code to delete files or folders. Files and folders are deleted directly, rather than deleted to the Recycle Bin. You can call the method provided by Microsoft.VisualBasic.dll.

First add a reference named Microsoft.VisualBasic.dll to the project, and then add the namespace

Using Microsoft.VisualBasic.FileIO;

The final example code is as follows:

usingsystem;usingmicrosoft.visualbasic.fileio;namespaceleaver{    classprogram    {         Staticvoidmain ( String[]args)        {             Console.WriteLine ("Delete Files to Recycle Bin");            Stringfilepath= "Leaver.txt";            Filesystem.deletefile (filepath,uioption.onlyerrordialogs,recycleoption.sendtorecyclebin);            Console.WriteLine ("Delete file complete");             Console.WriteLine ("Delete folder to Recycle Bin");            Stringdirpath= "Leaver";            Filesystem.deletedirectory (dirpath,uioption.onlyerrordialogs,recycleoption.sendtorecyclebin);            Console.WriteLine ("Delete folder Complete");        }    }

C # Delete files and folders to the Recycle Bin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.