StreamWriter reformatting output???
-
I have code that walks through the properties of an object and writes out the property name and value in UTF-16 format. One of the fields has a string date and time formatted as follows: yyyy-MM-ddThh:mm:ss When I step through the code, the data sent to my writer is formatted correctly. When I look at the output, however, it is now: yyyy-MM-dd hh:mm:ss AM. I know that it is not my writer logic doing this because it always just works with the object.ToString() method on everything. The base type of this object is string, not DateTime. First of all I cannot believe that StreamWriter is reformatting the data. Secondly I need to have it kept in the original format. Any suggestions to tell StreamWriter to keep its' hands off my data would be appreciated.
-
I have code that walks through the properties of an object and writes out the property name and value in UTF-16 format. One of the fields has a string date and time formatted as follows: yyyy-MM-ddThh:mm:ss When I step through the code, the data sent to my writer is formatted correctly. When I look at the output, however, it is now: yyyy-MM-dd hh:mm:ss AM. I know that it is not my writer logic doing this because it always just works with the object.ToString() method on everything. The base type of this object is string, not DateTime. First of all I cannot believe that StreamWriter is reformatting the data. Secondly I need to have it kept in the original format. Any suggestions to tell StreamWriter to keep its' hands off my data would be appreciated.
I think we need to see the code, I doubt very much that a streamwriter would reformat a datetime.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I think we need to see the code, I doubt very much that a streamwriter would reformat a datetime.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Christian, Trust me, I've been saying the same thing myself. Below is the code. I commented the line where I verified the format was still dateTtime and then looked at the output that was put to the file in notepad to see that the format was now data time AM. Messed up my head something fierce.
public sealed class Serialize:IDisposable { static StreamWriter output; //static FileStream output; /// <summary> /// Writes an opening Xml node to the stream /// </summary> /// <param name="fieldName"></param> public static void WriteOpen(string fieldName) { string buffer = String.Format("<{0}>", fieldName); //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length); output.Write( buffer ); } /// <summary> /// Writes a closing Xml node to the stream /// </summary> /// <param name="fieldName"></param> public static void WriteClose(string fieldName) { string buffer = String.Format("</{0}>", fieldName); //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length); output.Write( buffer ); } /// <summary> /// Writes a raw line of data to the stream /// </summary> /// <param name="rawData"></param> public static void WriteRaw(string rawData) { //output.Write(Encoding.UTF8.GetBytes(rawData), 0, rawData.Length); output.Write( rawData ); } /// <summary> /// Writes a formatted Xml line of data to the stream /// </summary> /// <param name="fieldName"></param> /// <param name="value"></param> public static void WriteLine(string fieldName, string value) { if (value.Length.Equals(0)) { string buffer = String.Format("<{0} />", fieldName); //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length); output.Write( buffer ); } else { string buffer = String.Format("<{0}>{1}</{0}>", fieldName, value); //output.Write(Encoding.UTF8.GetBytes(buffer),0,buffer.Length); // THIS IS WHERE I BROKE THE CODE AND VERIFIED THE BUFFER DATA PASSED TO