【发布时间】:2014-01-11 08:12:28
【问题描述】:
我有一个控制台文件,它有 6 个参数
我使用 C# 应用程序传递此参数,代码如下
try
{
intializeConnections();
string consolepath = System.Configuration.ConfigurationManager.AppSettings["ConsoleApp_backup"].ToString().Trim();
// string backupPath = System.Configuration.ConfigurationManager.AppSettings["DataBase_BackupPath"].ToString().Trim();
string backupPath = @"D:\backup\Smart Tracker\";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = consolepath;
// proc.StartInfo.Arguments = String.Format(consolepath, Pc, database, UserName, Password, "F", bacPath);
proc.StartInfo.Arguments = String.Format("{0} {1} {2} {3} {4} {5}", serverName, DatabaseName, UserId, pw, "F",backupPath );
//set the rest of the process settings
proc.Start();
clsGlobleFunction.InsertAuditTrailRecord_new(this.Name, "", "", "FullBackup Of Databse Done Sucessfull", clsGlobleFunction.ActiveUser);
MessageBox.Show("FullBackup Done Successfully!!!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "Give Correct Path in input !!");
}
它完美地工作,但是每当我传递其中有空间的参数时,就像在备份文件夹路径中的这段代码中一样,我正在传递文件夹路径 string backupPath = @"D:\backup\Smart Tracker\" 所以,它不起作用,控制台应用程序将空间视为参数的结尾, 并显示此错误..
那么,我如何传递有空格的参数!!!
【问题讨论】:
-
一如既往:Better use
Exception.ToString()instead ofException.Message获取调用堆栈等内容。
标签: c# sql-server console-application