• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38
  • Last Modified:

Convert VB.Net Process Object Arguments to C#

I am trying to convert VB.Net Process object arguments to C#. Please help me resolve the errors.

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

This C# code contains the errors:
      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

Full sub code:
       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

The following screenshot shows the C# errors:
Code Errors
0
Mark01
Asked:
Mark01
  • 2
1 Solution
 
Chinmay PatelEnterprise ArchitectCommented:
  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


Change it to

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:
No more build errors. Thank you, Chinmay Patel. Full code without build errors:
  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();
        }
0
 
Fernando SotoRetiredCommented:
Try using this line in place of the one you have
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

0
 
Mark01Author Commented:
Fernando Soto: I get build errors from your code. Thank you for the code.
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now