Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my programe i want to create a batch file and the string has to be displayed in a single line but when i execute my program it automatically splits into 3 lines. I dont knwo how to solve it.

C#
private void BtnCreate_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "";
            StreamWriter file = new StreamWriter("Export.bat");
            file.WriteLine("c: ");
            file.WriteLine("cd \\");
            file.WriteLine("cd Program Files ");
            file.WriteLine("cd VMware");
            file.WriteLine("cd VMware OVF Tool");

            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                 sName = row.Cells[0].Value.ToString();
                 sPath = row.Cells[1].Value.ToString();

                //richTextBox1.Text = richTextBox1.Text + Environment.NewLine + sName;
                file.WriteLine("start ovftool.exe --powerOffSource vi://" + TxtUsername.Text + ":" + TxtPassword.Text + "@"
                   + TxtIP.Text + sPath + " " + "\"" + TxtBrowsepath.Text + "\\" +  sName + "\\"
                   +  sName + ".ovf" + "\"" + Environment.NewLine);

                //Console.WriteLine("sName: " + sName + "sPath: " + sPath);

            }
            file.WriteLine("pause");
            MessageBox.Show("Batch File Created","Batch File");
            file.Close();
        }


Out put:
CSS
c:
cd \
cd Program Files
cd VMware
cd VMware OVF Tool
start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/UView-Web_Cardio_2015_v2 "C:\Users\demo\Desktop\
UView-Web_Cardio_2015_v2\
UView-Web_Cardio_2015_v2.ovf"

start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/asd/UV_CARDIO "C:\Users\demo\Desktop\
UV_CARDIO\
UV_CARDIO.ovf"

start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/vbnrt735w6%5c/MUSE_DEMO "C:\Users\demo\Desktop\
MUSE_DEMO\
MUSE_DEMO.ovf"

start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/4564/DEMO-EA "C:\Users\demo\Desktop\
DEMO-EA\
DEMO-EA.ovf"

start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/CCW5.1.1_DEMO "C:\Users\demo\Desktop\
CCW5.1.1_DEMO\
CCW5.1.1_DEMO.ovf"

start ovftool.exe --powerOffSource vi://izaz:pa55word@192.168.123.195/vbnrt735w6%5c/sdfasd34564/AWServer_3.1 "C:\Users\demo\Desktop\AWServer_3.1\AWServer_3.1.ovf"

pause
Posted
Comments
[no name] 17-Jul-15 9:17am    
Why is this a problem? Increase the number of columns on your command prompt window

1 solution

You need to surround the path with quotes because it has spaces in it.

cd VMware OVF Tool means it will move into directory VMware and also gives the parameters OVF and Tool (probably giving an error)
It should be cd "VMware OVF Tool"

You can add quotes in c# by escaping them, like: "this \" is a quote."

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900