In a regular string constant, the \
character is an escape character so, if you want to include a literal backslash, you need to escape it (with itself):
File.Delete("D:\\test\\bin\\Debug\\temptemp1.xls");
Otherwise \t
will become a tab, \b
a backspace and \D
give you your unrecognised escape sequence
error.
Alternatively, you use a raw string to avoid all the complexities that come from escaping:
File.Delete(@"D:\test\bin\Debug\temptemp1.xls");
which doesn't do the escaping.
The reason that it works with the forward slash /
is because Windows has, for a long time, been able to handle both styles (in the API, though not in the command interpreter cmd.exe
).