如何在C#win app的App.config中为Key赋值?

Anu*_*uya 0 .net c#

我在我的代码中使用以下字符串:

string AAR_FilePath = "\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";
Run Code Online (Sandbox Code Playgroud)

我不想在我的代码中硬核.所以我需要在我的app.config中使用它,我试图给出相同的值,

<add key="Path_SqlDump" value="\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\""></add>
Run Code Online (Sandbox Code Playgroud)

但由于引号,上面给出了错误.

我只需要,我应该能够分配 "\"C:\ MySQL\MySQL Server 5.0\bin\mysqldump \""

到一个字符串.怎么样 ?

public string AAR_FilePath = ConfigurationSettings.AppSettings["Path_SqlDump"].ToString();     

public void CreateScript_AAR()
{
    //AAR_FilePath = "\"C:\\MySQL\\MySQL Server 5.0\\bin\\mysqldump\"";
    string commandLine = @"" + AAR_FilePath + " -u" + DbUid + " -p" + DbPwd + " " + DbName + " > " + Path_Backup + FileName_Backup;  
    System.Diagnostics.ProcessStartInfo PSI = new System.Diagnostics.ProcessStartInfo("cmd.exe");
    PSI.RedirectStandardInput = true;
    PSI.RedirectStandardOutput = true;
    PSI.RedirectStandardError = true;
    PSI.UseShellExecute = false;
    System.Diagnostics.Process p = System.Diagnostics.Process.Start(PSI);
    System.IO.StreamWriter SW = p.StandardInput;
    System.IO.StreamReader SR = p.StandardOutput;
    SW.WriteLine(commandLine);
    SW.Close();
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*ohn 6

你没有在app.config中完成所有转义.那是一个C#的东西.只需将完整路径放在app.config中就像在命令提示符中那样.

<add key="Path_SqlDump" value="C:\MySQL\MySQL Server 5.0\bin\mysqldump\" />
Run Code Online (Sandbox Code Playgroud)