0

I have a console file, which takes 6 arguments enter image description here

I pass this argument using C# application, below code

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 !!"); } 

Its work perfectly, but whenever i pass argument which have space in it, like in this code in backup Folder path, i am passing folder path string backupPath = @"D:\backup\Smart Tracker\" so, its not working, console application consider space as a ending of argument, and showing this error.. enter image description here

so, how can i pass argument which have space!!!!

1

5 Answers 5

4

enclose your path within single quotes to consider the whole path as single string argument.

string backupPath = @"'D:\backup\Smart Tracker\'"; 
Sign up to request clarification or add additional context in comments.

Comments

3

Encapsulate the spaced argument in quotations. I.E. @"\"D:\backup\Smart Tracker\"";

Comments

0

Try using Environment.CommandLine, you'll have to parse it or wrap in quotes.

1 Comment

Would you believe me if I said yes?
0

Escape the path with single single quotes ' '

string backupPath = @"'D:\backup\Smart Tracker\'"; 

Or if you prefer:

string backupPath = @"\"D:\backup\Smart Tracker\""; 

1 Comment

thanks for your attention, i try both but its not worked
0

I try below code and its works perfectly !!!

 char c = Convert.ToChar(34); string backupPath = c + @"D:\backup\Smart Tracker" + c; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.