What is the difference between single slash and double slash in file path for Windows operating system such as
c:\\Personal\MyFolder\\MyFile.jpg
and
c:\Personal\MyFolder\MyFile.jpg
What if I use the single or double slash because I have tried both for storing images in my code (in webconfig file) and both of them work fine.
Is there any difference??
Windows ignores double backslashes. So while the second syntax with \
is correct and you should use that one, the first with \\
works too.
The only exception is double-backslash at the very beginning of a path that indicates a UNC path.
See Universal Naming Convention.
Though note that in many programming languages like C, C++, Java, C#, Python, PHP, Perl, a backslash works as an escape character in string literals. As such, it needs to be escaped itself (usually with another backslash). So in these languages, you usually need to use a double backslash in the string literal to actually get a single backslash for a path. So for example in C#, the following string literal is actually interpreted as C:\Personal\MyFolder\MyFile.jpg
:
var path = "C:\\Personal\\MyFolder\\MyFile.jpg";
Though there are alternative syntaxes. For example in C#, you can use the following syntax with the same result:
var path = @"C:\Personal\MyFolder\MyFile.jpg";