سلام بر تمامی برنامه نویسان #C 😉 در این مطلب از وب سایت پروگرم 98 آموزش استفاده از FileSystemWatcher برای تشخیص تغییرات فایل در سی شارپ #C را آماده کردم. انشاالله که این کد براتون مفید باشه.
خروجی کد به این صورت می باشد :
NOTIFICATION: C:\Java_Dev\WEB\dev\CSharp\test.bin' was Deleted
کد استفاده از FileSystemWatcher برای تشخیص تغییرات فایل در سی شارپ #C :
using System;
using System.IO;
using System.Windows.Forms;
static class MainClass
{
static void Main()
{
using (FileSystemWatcher watch = new FileSystemWatcher())
{
watch.Path = Application.StartupPath;
watch.Filter = "*.*";
watch.IncludeSubdirectories = true;
watch.Created += new FileSystemEventHandler(OnCreatedOrDeleted);
watch.Deleted += new FileSystemEventHandler(OnCreatedOrDeleted);
watch.EnableRaisingEvents = true;
if (File.Exists("test.bin"))
{
File.Delete("test.bin");
using System.IO;
using System.Windows.Forms;
static class MainClass
{
static void Main()
{
using (FileSystemWatcher watch = new FileSystemWatcher())
{
watch.Path = Application.StartupPath;
watch.Filter = "*.*";
watch.IncludeSubdirectories = true;
watch.Created += new FileSystemEventHandler(OnCreatedOrDeleted);
watch.Deleted += new FileSystemEventHandler(OnCreatedOrDeleted);
watch.EnableRaisingEvents = true;
if (File.Exists("test.bin"))
{
File.Delete("test.bin");