Пример #1
0
        /// <summary>Write to file name</summary>
        /// <param name="pathAndFile">The path and file.</param>
        /// <param name="txt">The text.</param>
        /// <param name="writeAction">The write action.</param>
        public void File_Write(string pathAndFile, string txt, enIO_WriteAction writeAction = enIO_WriteAction.WriteFile)
        {
            if (writeAction == enIO_WriteAction.OverWriteFile)
            {
                File.WriteAllText(pathAndFile, txt);
                return;
            }

            bool fileExist = _io.File.Exists(pathAndFile);

            if (writeAction == enIO_WriteAction.WriteFile)
            {
                if (fileExist)
                {
                    var ex = new ArgumentException("Error! Can not write to file because it already exists.", nameof(writeAction));
                    ex.zLogLibraryMsg();
                    throw ex;
                }
                else
                {
                    File.WriteAllText(pathAndFile, txt);
                }
            }
            else if (writeAction == enIO_WriteAction.AppendFile)
            {
                if (_io.File.Exists(pathAndFile))
                {
                    txt = "".NL() + txt;                               // Add extra space into file
                }
                File.AppendAllText(pathAndFile, txt);
            }
        }
Пример #2
0
        /// <summary>Write to file name</summary>
        /// <param name="pathAndFile">The path and file.</param>
        /// <param name="lines">The lines.</param>
        /// <param name="writeAction">The write action.</param>
        public void File_Write(string pathAndFile, string[] lines, enIO_WriteAction writeAction = enIO_WriteAction.WriteFile)
        {
            var txt = lines.zTo_Str("".NL());

            File_Write(pathAndFile, txt, writeAction);
        }