C# - retrieve file path from config file - @ doesn't do it's magic
- by Bart
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!