1

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?

Ferus7
  • 707
  • 1
  • 10
  • 23
  • 1
    Network paths start with \\ symbol, in c# when you want to write that you need to use verbatim string or just escape backslashes. If you escape backslashes you will get \\\\ – Ruben Vardanyan May 03 '17 at 10:01
  • So, if I don't add @, c# gets it like a backslash? – Ferus7 May 03 '17 at 10:06
  • 2
    You have to use a proper UNC path. It is `"\\\\machname\\share\\dir\\file.ext"`. Or `@"\\machname\share\dir\file.ext"`. Do avoid an IP-address, they change. – Hans Passant May 03 '17 at 10:08
  • @Ferus7 yes, you need to escape some characters in string. see the answer bellow for explanation – Ruben Vardanyan May 03 '17 at 10:09
  • I read the static IP Address from an xml, Thank you all, now I understand it – Ferus7 May 03 '17 at 10:10

1 Answers1

2

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

Karthick Raju
  • 757
  • 8
  • 29
  • I think i understand it, if I don't use a verbatim, the path will start with \ instead of \\ and it will refer to C: – Ferus7 May 03 '17 at 10:08