System.IO.FileInfo.AppendText C# (CSharp) Method

AppendText() public method

public AppendText ( ) : StreamWriter
return StreamWriter
        public StreamWriter AppendText()
        {
            return new StreamWriter(FullPath, append: true);
        }

Same methods

FileInfo::AppendText ( ) : System.IO.StreamWriter

Usage Example

Example #1
0
        public static void Write(EventRecord Record)
        {
            if (!System.IO.Directory.Exists(baseDirectory))
            {
                System.IO.Directory.CreateDirectory(baseDirectory);
            }

            string OutputFilename = System.IO.Path.Combine(baseDirectory, string.Format("Megamind_{0}", System.DateTime.Today.ToString("yyyyMMdd")));

            System.IO.FileInfo fi = new System.IO.FileInfo(OutputFilename);
            bool AddHeader        = !fi.Exists;

            using (var sw = fi.AppendText())
            {
                if (AddHeader)
                {
                    sw.WriteLine(Record.GetHeader());
                }

                if (!Record.EventTime.HasValue)
                {
                    Record.EventTime = System.DateTime.Now;
                }

                sw.WriteLine(Record.ToString());
                sw.Flush();
                sw.Close();
            }
        }
All Usage Examples Of System.IO.FileInfo::AppendText