23 Aralık 2010 Perşembe

Find and Replace Text in Text / HTML Files

public void ReplaceInFile(string filePath,string replaceText,string findText)
{
    try
    {
         System.IO.StreamReader objReader;
         objReader= new System.IO.StreamReader(filePath);
         string content= objReader.ReadToEnd();
         objReader.Close();

         content= Regex.Replace(content,findText,replaceText);

         StreamWriter writer= new StreamWriter(filePath);
         writer.Write(content);
         writer.Close();
    }

     catch(IOException iexp)
{
   throw;
}

Hiç yorum yok:

Yorum Gönder