Exemple #1
0
 public static string GetPreview(string lines, ReplaceSettings replace = null, string nameOfFile = null)
 {
     if (replace != null)
     {
         string       retVal    = "";
         string       aLine     = null;
         StringReader strReader = new StringReader(lines);
         while ((aLine = strReader.ReadLine()) != null)
         {
             retVal += replace.Replace(aLine, nameOfFile) + "\n";
         }
         return(retVal);
     }
     else
     {
         return(lines);
     }
 }
Exemple #2
0
        public static bool CreateFile(string nameOfFile, string extention, string lines, ReplaceSettings replaceSettings)
        {
            bool   retVal    = false;
            string directory = GetProjectDirectory();

            if (directory != null)
            {
                string path = directory + "\\" + nameOfFile + extention;
                if (PathValidCheck(path))
                {
                    // Create a new file
                    StreamWriter sw = File.CreateText(path);
                    if (lines != null && lines != "")
                    {
                        string       aLine     = null;
                        StringReader strReader = new StringReader(lines);
                        if (replaceSettings != null)
                        {
                            while ((aLine = strReader.ReadLine()) != null)
                            {
                                sw.WriteLine(replaceSettings.Replace(aLine, nameOfFile));
                                retVal = true;
                            }
                        }
                        else
                        {
                            while ((aLine = strReader.ReadLine()) != null)
                            {
                                sw.WriteLine(aLine);
                                retVal = true;
                            }
                        }
                    }
                    sw.Close();
                }
            }
            return(retVal);
        }