- [DEVEXPRESS] Chia sẻ source code cách tạo biểu đồ sơ đồ tổ chức công ty Org Chart trên Winform C#
- [C#] Hướng dẫn tạo Auto Number trên Datagridview winform
- [DATABASE] Hướng dẫn tạo Procedure String Split in Mysql
- [C#] Thiết lập dấu (,) hay dấu (.) ở định dạng số đúng với định dạng số Việt Nam
- [C#] Chia sẻ source code Game Spin Lucky Wheel
- [C#] Hướng dẫn Encode and Decode HTML
- Danh sách tài khoản ChatGPT miễn phí - Hướng dẫn tạo tài khoản Chat Open AI GPT tại Việt Nam
- [C#] Hướng dẫn thay đổi giao diện ứng dụng Winform theo giao diện của Windows
- [VB.NET] Hiệu ứng Acrylic, Mica, Tabbed Blur Effect trên Winform
- [DEVEXPRESS] Hướng dẫn sử dụng HTML Template trên Combobox Edit
- [C#] Chia sẻ source code Orange Rain in Winform
- [DEVEXPRESS] Hướng dẫn sử dụng HTML Template trên XtraMessageBox Winform Devexpress 22.2.3
- [DEVEXPRESS] Hướng dẫn sử dụng HTML and CSS Code Viewer trên Winform
- [C#] Number Effect Counter up and down in winform
- [C#] Hướng dẫn Supend and Resume Process ID in Winform
- [C#] Hiển thị line number trên Richtextbox Winform
- [C#] Fake Blue Screen BSOD in winform
- [C#] Chia sẽ code demo sử dụng Async Parallel Foreach and For in Winform
- [C#] Sử dụng ActionBlock run X task at time winform
- [C#] Hướng dẫn sử dụng Property Grid để lưu và tải lại thông tin cấu hình user trên winform
[C#] Empty Recycle Bin trong lập trình csharp
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:
Đầ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 :)