Search code examples
c#pathxmldocumentverbatim-string

How work network paths in C#?


I'm having a doubt about this

I tried to save a xmlDocument in a network device folder, not mapping.

Where:

config.plc.Path ="\\IpAdress\\folder\\";

doc.Save(config.plc.Path + "file.xml");

It was throwing an exception, and I just fixed it using the '@'

doc.Save(@config.plc.Path + "file.xml");

When I add the parameter as verbatim string with @, it gets like this:

config.plc.Path ="\\\\IpAdress\\\\folder\\\\";

is the first time I see a path like this, with

\\\\

can someone help me to understand this?


Solution

  • It's simple, \\ is just an escape sequence for \. @ (Verbatim String) has to be used to avoid this