NEWS

[C#] Empty Recycle Bin trong lập trình csharp

[C#] Empty Recycle Bin trong lập trình csharp
Đăng bởi: Thảo Meo - Lượt xem: 5398 08:10:18, 18/05/2018DEVEXPRESS   In bài viết

Hi! xin chào các bạn, bài viết hôm nay, mình sẽ hướng dẫn các bạn cách xóa các tâp tin và thư mục trong thùng rác (Recyle Bin) bằng ngôn ngữ lập trình C#.

Để xóa thư mục và tập tin trong Recycle Bin, chúng ta sử dụng phương thức  SHEmptyRecyleBin() trong library Shell32.dll

Dưới đây là giao diện demo:

empty recycle bin trong c#

Đầu tiên các bạn cần import thư viện vào

using System.Runtime.InteropService;

Source code ứng dụng c#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace RecyleBin
{
    enum RecycleFlag : int
    {
        SHERB_NOCONFIRMATION = 0x00000001, // No confirmation, when emptying 
        SHERB_NOPROGRESSUI = 0x00000001, // No progress tracking window during the emptying of the recycle bin
        SHERB_NOSOUND = 0x00000004 // No sound whent the emptying of the recycle bin is complete
    }

    public partial class Form1 : Form
    {

        //include the Shell32.exe
        [DllImport("Shell32.dll")]
        static extern int SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlag dwFlags);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Clear Button
            SHEmptyRecycleBin(IntPtr.Zero, null, RecycleFlag.SHERB_NOSOUND | RecycleFlag.SHERB_NOCONFIRMATION);

            MessageBox.Show("Your RecyleBin is Clear now !! ");

        }
    }
}

HAVE FUN :)

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Empty Recycle Bin trong lập trình csharp
Đăng bởi: Thảo Meo - Lượt xem: 5398 08:10:18, 18/05/2018DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.