Reading Files in Asp.net or C# and Search for a particular text in files in a specific directory


using (StreamReader sr = new StreamReader("FilePath" + "Config.dat"))
{
    sConfigText = sr.ReadToEnd();
}
try
{
objEditvmta = new StringBuilder();
string Pickfile = "identifystring";
if (sConfigText.Contains(Pickfile))
{
   StartPoint = sConfigText.Substring(0, sConfigText.IndexOf(Pickfile)) + Environment.NewLine;
   RemainingText = sConfigText.Substring(StartPoint.Length - 1);
   EntairText = RemainingText.Substring(RemainingText.IndexOf("EndingstringValue") + "EndingstringValue Length");
   objVmta.Append(StartPoint.TrimEnd());
   objVmta.Append(EntairText.TrimEnd());
   sConfigEditData = objVmta.ToString();
   FinalDeletePattern = sConfigEditData;
   FileStream fsPattern = File.OpenWrite("FilePath" + "FileName");
   Encoding encPattern = Encoding.ASCII;
   byte[] restPattern = encPattern.GetBytes(sConfigEditData.ToString());
   fsPattern.Write(restPattern, 0, sConfigEditData.Length);
   fsPattern.Flush();
   fsPattern.Close();
   fsPattern.Dispose();
}
sConfigEditData = string.Empty;
objEditvmta = null;
StartPoint = string.Empty;
RemainingText = string.Empty;
EntairText = string.Empty;
}
catch (Exception ex)
{

thow;

}

Comments