1

I receive a string like "c:\test\abc.xlsx" which indicates me the excel path. I have to depend on what i receive and cannot hard code it. Now what how should i make sure the the single "\" is escaped and it becomes "\"

string **PATH** = "c:\test\abc.xlsx"
string conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=**PATH**;Extended Properties=Excel 12.0;";

2 Answers 2

1

The single "\" doesn't appear to be escaped properly.

Try: string path = @"c:\test\abc.xlsx";

The leading @ sign will escape it properly for you

Sign up to request clarification or add additional context in comments.

Comments

1

Should be simple:

String thePath = "c:\\test\\abc.xlsx"
String conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + thePath + ";Extended Properties=Excel 12.0;";

1 Comment

Hey I am new to C# ; but if you see i should replace the single "\" to "\\" for the path, else the code gives an error, how do i do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.