Избавьтесь от try
/ finally
:
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Open, FileAccess.Read))
using (TextReader tr = new StreamReader(fs))
{
fs.Flush();
return tr.ReadToEnd();
}
using
уже делает что-то вроде этого:
{
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Open, FileAccess.Read);
try
{
// code inside the `using` goes here
}
finally
{
fs.Dispose();
}
}
А утилизация, по самой своей природе, закроет поток.
См. этот вопрос для получения дополнительной информации о using
.