Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Unrecognized Escape Sequence Error

Posted on 2016-10-02
5
Medium Priority
?
135 Views
Last Modified: 2016-10-02
I’m trying to write some simple C# code in a winform app that gets the same results as a VB.Net sub. Please help me correct the error. The following VB (in a winform app) code runs without any errors:

Dim retval As String
Dim ls_temp As String
ls_temp = "C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe " & _
"-e ""C:\test\Email_Test_1aa.rpt"""
retval = Shell(ls_temp)

The following C# code results in an “Unrecognized escape sequence” error:
string retval;
string ls_temp;
retval = C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe " +
"-e ""C:\test\Email_Test_1aa.rpt""";
0
Comment
Question by:Mark01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
David Johnson, CD, MVP earned 1200 total points
ID: 41825510
Change the single \'s to \\'s to escape the escape sequence
\t = tab character
\r = return character
\n = newline character

  string retval;
            retval = "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe " + "-e "  + "C:\\test\\Email_Test_1aa.rpt";
            Console.WriteLine(retval);
            Console.ReadLine();

Open in new window

0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 800 total points
ID: 41825512
An alternative is to use the @ symbol with the string, this tells the compiler to ignore all escape sequence characters.
@"C:\Program Files (x86)\Visual CUT 11\Visual CUT.exe "  is the same as "C:\\Program Files (x86)\\Visual CUT 11\\Visual CUT.exe "


ps. I'm surprised the VB code worked, there are spaces in the path
0
 

Author Comment

by:Mark01
ID: 41825557
That resolved the error. Can someone give me a hint to the C# equivalent of the following VB code:
        retval = Shell(ls_temp)
0
 
LVL 83

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 1200 total points
ID: 41825570
Long-winded but it works
 Process process = new Process();
        process.StartInfo.FileName = "[program name here]";
        process.StartInfo.Arguments = "[arguments here]";
        process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
        process.Start();
        process.WaitForExit();
        int code = process.ExitCode;

Open in new window


https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx
0
 

Author Closing Comment

by:Mark01
ID: 41825593
Thank you, David and Andy.
0

Featured Post

URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question