Convert VB.Net Process Object Arguments to C#

I am trying to convert VB.Net Process object arguments to C#, but the application (Visual Cut) will not run. Please help me resolve the errors.

There are no build errors for the following, but I get a Visual Cut “Failed: Command Line Argument not in Double Quotes” error.
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = string.Concat("-e ", "C:\\test_3\\People_1.rpt ","Export_Format:Adobe Acrobat (pdf) ", "Export_File:C:\\test_3\\People_1.pdf");

            p.StartInfo = psi;
            p.Start();
        }

Open in new window


I get "Unexpected character '\'" build errors with the following:
     
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = string.Concat("-e ", ""C:\\test_3\\People_1.rpt "","Export_Format:Adobe Acrobat (pdf) "", ""Export_File:C:\\test_3\\People_1.pdf"");

            p.StartInfo = psi;
            p.Start();
        }

Open in new window

This VB code works:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim startInfo As New ProcessStartInfo
        startInfo.FileName = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe"
        startInfo.Arguments = "-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""
        Process.Start(startInfo)
    End Sub

Open in new window

Mark01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
This is your VB.Net
        startInfo.Arguments = "-e ""C:\test_3\People_1.rpt"" ""Export_Format:Adobe Acrobat (pdf)"" ""Export_File:C:\test_3\People_1.pdf"""

and (I hope) this is the C# equivalent.  I might have missed a \" somewhere
        startInfo.Arguments = "-e \"C:\\test_3\\People_1.rpt\" \"Export_Format:Adobe Acrobat (pdf)\" \"Export_File:C:\\test_3\\People_1.pdf\""


You can use the \" combination to include a quote symbol in a string
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ktaczalaCommented:
Try This
psi.Arguments = string.Concat("-e" + "\" " , "\"" + "C:\\test_3\\People_1.rpt" + "\" ", "\"" + "Export_Format:Adobe Acrobat (pdf)" + "\" ", "\"" + "Export_File:C:\\test_3\\People_1.pdf" + "\"");

Open in new window

0
Mark01Author Commented:
This worked; the file exported. Full sub:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "-e \"C:\\test_3\\People_1.rpt\" \"Export_Format:Adobe Acrobat (pdf)\" \"Export_File:C:\\test_3\\People_1.pdf\"";

            p.StartInfo = psi;
            p.Start();
        }
t

@ktaczala: This did not work. Visual Cut only starts and open the grid. Full Sub:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = string.Concat("-e" + "\" ", "\"" + "C:\\test_3\\People_1.rpt" + "\" ", "\"" + "Export_Format:Adobe Acrobat (pdf)" + "\" ", "\"" + "Export_File:C:\\test_3\\People_1.pdf" + "\"");

            p.StartInfo = psi;
            p.Start();
        }

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Mark01Author Commented:
Thank you, AndyAinscow and ktaczala.
0
Fernando SotoRetiredCommented:
Change the line of code that starts like "psi.Arguments =" in the C# program to this
psi.Arguments = "-e \"C:\\test_3\\People_1.rpt\" \"Export_Format:Adobe Acrobat (pdf)\" \"Export_File:C:\\test_3\\People_1.pdf\"";

Open in new window


Your VB code produces this
-e "C:\test_3\People_1.rpt" "Export_Format:Adobe Acrobat (pdf)" "Export_File:C:\test_3\People_1.pdf"

Open in new window

and the line above produces this
-e "C:\test_3\People_1.rpt" "Export_Format:Adobe Acrobat (pdf)" "Export_File:C:\test_3\People_1.pdf"

Open in new window

As you can see identical.
0
Mark01Author Commented:
@Fernando Soto: Your code worked, the report exported. Thank you. Full sub:
        private void btnOpenPDF_Click(object sender, EventArgs e)
        {
            Process p = new Process();
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.UseShellExecute = true;
            psi.FileName = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe";
            psi.Arguments = "-e \"C:\\test_3\\People_1.rpt\" \"Export_Format:Adobe Acrobat (pdf)\" \"Export_File:C:\\test_3\\People_1.pdf\"";
                        p.StartInfo = psi;
            p.Start();
        }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.