private string GetFileContent(string path)
{
if(File.Exists(HttpContext.Current.Server.MapPath(path)))
{
FileStream fs=null;
try
{
fs = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Open, FileAccess.Read);
using (TextReader tr = new StreamReader(fs))
{
fs.Flush();
return tr.ReadToEnd();
}
}
finally
{
fs.Close();
}
}
}
If FileStream fs is assigned to null code is running without warnings but I don't want to assign filestream to null i.e., fs=null in using Statement.
So, what is the correct way of writing it without assigning null value?