文件系统监视器路径不能与app.config一起工作
本文关键字:config 一起 工作 app 监视器 路径 不能 文件系统 | 更新日期: 2023-09-27 18:18:59
当我使用app.config作为路径时,它不会监视任何内容手动填充它工作的路径。我不明白它是如何使用手动路径工作的,而不是使用appconfig路径
请求帮助!
using System;
using System.IO;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace ChaloSync
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool pause = false;
String source = ConfigurationManager.AppSettings[@"Directory1"];
String target = ConfigurationManager.AppSettings[@"Directory2"];
static void config()
{
foreach (string key in ConfigurationManager.AppSettings)
{
string value = ConfigurationManager.AppSettings[key];
MessageBox.Show(value);
}
}
static void database_query()
{
var connection = new MySqlConnection(
"server=localhost;user id=robin;password=***;database=destination;");
connection.Open();
string query = "INSERT INTO files (name,size,last_edit,extension) VALUES('query3',20000,'2013-6-19','.voorbeeld')";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.ExecuteNonQuery();
}
private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File changed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File created> " + e.FullPath + " -Date:" + DateTime.Now);
}
private void fileSystemWatcher1_Deleted(object sender, System.IO.FileSystemEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File deleted> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void fileSystemWatcher1_Renamed(object sender, System.IO.RenamedEventArgs e)
{
if (!pause)
{
listBox1.Items.Add("File renamed> " + e.FullPath + " -Date:" + DateTime.Now);
}
}
private void Start_Click(object sender, EventArgs e)
{
fileSystemWatcher1.Path = source;
if (!pause)
{
pause = true;
Start.Text = "Pause";
fileSystemWatcher1.EnableRaisingEvents = true;
}
else
{
pause = false;
Start.Text = "Start";
}
}
}
}
应用程序。配置代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Directory1" value="C:'Users'*****'Desktop'dir 1"/>
<add key="Directory1" value="C:'Users'*****'Desktop'dir 2"/>
</appSettings>
</configuration>
在你的app.config中,两个设置都将" deidirectory1 "定义为键。将第二个替换为"Directory2",就可以了:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Directory1" value="C:'Users'd.brock'Desktop'dir 1"/>
<add key="Directory2" value="C:'Users'd.brock'Desktop'dir 2"/>
</appSettings>
</configuration>