I want to write some data in Excel in C # using COM, but I have a problem with saving. Check out the code:
workSheet.SaveAs("c:/users/amare/sub.xls");
The above code will throw an error:
"Microsoft Excel cannot open the file c: //users/amare/sub.xls."
But the code below works fine:
workSheet.SaveAs("c:\\users/amare/sub.xls");
workSheet.SaveAs(@"c:\users\amare\sub.xls");
Now I am completely confused by this situation. I know 2) and 3) is absolutely right, but I'm used to writing code like 1):
StreamWriter sw = new StreamWriter("c:/users/amare/desktop/file.txt"); sw.WriteLine("foo-bar"); sw.close();
It always works well. So I want to know why this is not this time. Apparently, C # chose the wrong path in 1).
source share