Hi
getting error - Unrecognized excape sequence
C#
attachment.FileName = "@10.0.1.10\SAP_Attachments\O_204673_20250314_205951");Thanks
Hi
getting error - Unrecognized excape sequence
attachment.FileName = "@10.0.1.10\SAP_Attachments\O_204673_20250314_205951");Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sophia CarterRank #4,018 · 371 reputationPosted Mar 15, 2025, 4:35 AM EDT
It seems like the error you are encountering is related to an unrecognized escape sequence in C# code. In the provided code snippet:
attachment.FileName = "@10.0.1.10\SAP_Attachments\O_204673_20250314_205951");The issue lies with the backslashes used in the file path. In C# strings, backslashes are used to escape characters, meaning they are interpreted as special characters. If you want to include a backslash as a literal character in a string, you need to escape it by using another backslash before it.
To resolve the error, you can correct the file path string by escaping the backslashes properly, like this:
attachment.FileName = "@10.0.1.10\\SAP_Attachments\\O_204673_20250314_205951");By doubling the backslashes, you are telling the C# compiler to treat them as literal backslashes in the string. This adjustment should resolve the "Unrecognized escape sequence" error you are facing.
If you encounter any further issues or have additional questions, feel free to let me know!
Jignesh KumarRank #91 · 22.9K reputationPosted Mar 15, 2025, 5:45 AM EDT
Hello Ramco,
You need to add a Verbatim String (
@before the string), just check on this it should resolve your issueattachment.FileName = @"\\10.0.1.10\SAP_Attachments\O_204673_20250314_205951";Prasad RaveendranRank #320 · 7.8K reputationPosted Mar 16, 2025, 1:46 AM EDT
Solution
You need to use double backslashes (
\\) or a verbatim string literal (@prefix) to correctly format the file path.Option 1: Escape Backslashes
attachment.FileName = "C:\\10.0.1.10\\SAP_Attachments\\O_204673_20250314_205951";Option 2: Use a Verbatim String Literal
attachment.FileName = @"C:\10.0.1.10\SAP_Attachments\O_204673_20250314_205951";Note
Your original string starts with
@, which is incorrect syntax. If you meant to use a verbatim string, you should write:attachment.FileName = @"\\10.0.1.10\SAP_Attachments\O_204673_20250314_205951";This correctly represents a UNC (Universal Naming Convention) path for a network share.