[英]Filesystem watcher path not working with app.config
When i use app.config as a path it wont watch anything But if i Manually fill in the path it does work. 当我将app.config用作路径时,它不会监视任何内容,但是如果我手动填写该路径,它将起作用。 I dont get how it does work with the manual path but not with the appconfig path 我不知道它如何与手动路径一起工作,但与appconfig路径一起工作
HELP REQUESTED.! 要求帮助。
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";
}
}
}
}
app.config code app.config代码
<?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>
In your app.config both settings define "Deirectory1" as key. 在您的app.config中,两个设置都将“ Deirectory1”定义为键。 Replace the second one with "Directory2" and it will work: 将第二个替换为“ 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.