String.replace removing backslash

MxDesign

New Member
I have a question and I am sure it is simple but its not working in my code. I am creating a log file and I want to concatenate the date to the file name so they know when the log was generated. My string.replace isn't removing "\" from my date which I have converted to string.See code below:\[code\] string DateNow = Convert.ToString(System.DateTime.Now); DateNow = DateNow.Substring(0, 10); DateNow.Replace(@"\\", "-"); string FileName = "log" + DateNow + ".txt"; // Write values to textfile and save to Log folder using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/Log" + FileName))) { sw.WriteLine(System.DateTime.Now); sw.WriteLine("New user created"); sw.WriteLine("Username is: " + username); sw.WriteLine("Password is: " + password); sw.WriteLine("Company is: " + company); sw.WriteLine("Email is: " + email); sw.Dispose(); sw.Close(); }\[/code\]This will throw an exception because file names in windows can't contain \ character. Any ideas why the replace method isn't working?Thanks.
 
Back
Top