Hi guys,
I'm currently working on a web service that retrieves an XML message, archives it and then processes it further. The archive folder is read from the Web.config. This is what the archive method looks like
private void Archive(System.Xml.XmlDocument xmlDocument)
{
try
{
string directory = System.Configuration.ConfigurationManager.AppSettings.Get("ArchivePath");
ParseMessage(xmlDocument);
directory = string.Format(@"{0}\{1}\{2}", directory, _senderService, DateTime.Now.ToString("MMMyyyy"));
System.IO.Directory.CreateDirectory(directory);
string Id = _messageID;
string senderService = _senderService;
xmlDocument.Save(directory + @"\" + DateTime.Now.ToString("yyyyMMdd_") + Id + "_" + System.Guid.NewGuid().ToString().Substring(0, 13) + ".xml");
}
The path structure I retrieve is C:\Program Files\Subfolder\Subfolder. In the development, QA, UAT and PRD environments everything works fine. But on another machine I now need to install the web service on (which I cannot debug, unfortunately), the directory string is 'C:Files'. Just to be sure I double checked the .NET version on the different machines (I thought perhaps the usage of @ before a string was version-dependent); all machines use 2.0.50727.
Does anyone recognize this problem?
Thanks in advance!
EDIT: I see the @ before the directory variable has caused some confusion regarding the question I asked. It was not about that @ (in fact, that should not have been there. I have removed it).
My question (rephrased) is: when you place an @ before a quoted string, like @"c:\folder\subfolder", it ensures that the backslashes are not interpreted as escape characters, right? What could be the cause of it working on one machine, but not working on another? (I do agree with the answers stating to use Path.Combine by the way. I'm just curious what causes this inconsistent behaviour)