예제 #1
0
        ///<summary>
        /// Append to a file.
        ///</summary>
        ///<param name="fileName">
        /// The filename to be used in format: [filename].[extention].
        ///</param>
        ///<param name="savePath">
        /// The folder to save in.
        /// If not setted, the file will be saved in "pSavepath".
        ///</param>
        public string FileAppend(string fileName = "", string savePath = "")
        {
            if (!Initial("FileAppend()"))
            {
                return(null);
            }
            try
            {
                if (fileName == "")
                {
                    fileName = FileName;
                }
                if (savePath == "")
                {
                    savePath = pSavepath + fileName;
                }
                else
                {
                    if (savePath[savePath.Length - 1] != '\\')
                    {
                        savePath += '\\';
                    }
                    savePath += fileName;
                }
                if (Validators.ValidateWriteAccess(savePath) == false)
                {
                    Fault("You don't have write access!");
                    return(savePath);
                }

                object obj = GetS();
                if (obj is string == false && obj is string[] == false && obj is IEnumerable <object> == false)
                {
                    Fault("Invalid value!");
                    return(null);
                }

                if (obj is string)
                {
                    string str = obj as string;
                    IO.Append(savePath, str);
                    Success(fileName + " Saved! " + str.Length.ToString() + " chars of data written!");
                    return(savePath);
                }
                else if (obj is string[])
                {
                    string str = String.Join(Environment.NewLine, obj as string[]);
                    IO.Append(savePath, str);
                    Success(fileName + " Saved! " + (obj as string[]).Count().ToString() + " lines written!");
                    return(savePath);
                }
                Fault("Invalid value!");
                return(savePath);
            }
            catch (Exception ex)
            {
                Exceptional(ex);
                return(null);
            }
        }
예제 #2
0
        ///<summary>
        /// Append to a file.
        ///</summary>
        ///<param name="s">
        /// The collection of strings to be appended.
        ///</param>
        ///<param name="fileName">
        /// The filename to be used in format: [filename].[extention].
        ///</param>
        ///<param name="savePath">
        /// The folder to save in.
        /// If not setted, the file will be saved in "pSavepath".
        ///</param>
        public string FileAppend(IList <string> s, string fileName = "", string savePath = "")
        {
            if (!Initial("FileAppend()"))
            {
                return(null);
            }
            try
            {
                if (fileName == "")
                {
                    fileName = FileName;
                }
                if (savePath == "")
                {
                    savePath = pSavepath + fileName;
                }
                else
                {
                    if (savePath[savePath.Length - 1] != '\\')
                    {
                        savePath += '\\';
                    }
                    savePath += fileName;
                }
                if (Validators.ValidateWriteAccess(savePath) == false)
                {
                    Fault("You don't have write access!");
                    return(savePath);
                }

                IO.Append(savePath, s);
                Success(fileName + " Saved! " + s.Count().ToString() + " lines written!");
                return(savePath);
            }
            catch (Exception ex)
            {
                Exceptional(ex);
                return(null);
            }
        }