I am creating gui for a command line program. In txtBoxUrls [TextBox], the file path is entered line by line. If the file path contains spaces , the program does not work properly. The program is given below.
string[] urls = txtBoxUrls.Text.ToString().Split(new char[] { '\n', '\r' });
string s1;
string text;
foreach (string s in urls)
{
if (s.Contains(" "))
{
s1 = @"""" + s + @"""";
text += s1 + " ";
}
else
{
text += s + " ";
}
}
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = @"wk.exe";
proc.StartInfo.Arguments = text + " " + txtFileName.Text;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string strOutput = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
For example, if the file path is specified in txtBoxUrls, it is "C: \ VS2008 \ Projects \ web2pdf \ web2pdf \ bin \ Release \ Test Page.htm", the program will not work. This path to the file with double quotes will work on the Windows command line (I do not use the graphical interface). What will be the solution.
Vinod source
share