Hi,
Please find the solution of the same.
Note: I have used the 'Server' as keyword to find the DataServer value.
<blockquote class="FQ"><div class="FQA">Quote:</div>/// <summary>
/// This method will search for a Key value and return its value
/// </summary>
/// <param name="filePath"></param>
/// <param name="referencevalue"></param>
private static void SearchString(string filePath, string referencevalue, string delimiter)
{
try
{
if (System.IO.File.Exists(filePath))
{
StreamReader sr = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
string Originaldata = string.Empty;
string Updatedata = string.Empty;
//Read Line by Line
string[] file = System.IO.File.ReadAllLines(filePath);
foreach (string line in file)
{
if (line.Contains(referencevalue))
{
string[] arrValue = Regex.Split(line, delimiter);
string value = arrValue[1];
Console.WriteLine("The Value of Server is " + value);
}
}
}
else
{
Console.WriteLine("[Error] File does not exists in path -" + filePath);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
</blockquote>
Hope it helps. Thanks.