1

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";

        }

    }

}
}

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>
4

1 に答える 1

1

app.config で、両方の設定で「Deirectory1」をキーとして定義します。2 番目のものを「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>
于 2013-06-19T13:34:22.860 に答える