using System; using System.IO; using System.Text; using System.Web.Mvc; using DR.FV2016.Service; using StructureMap; namespace DR.FV2016.Web.Helpers { public static class HtmlHelper { public static MvcHtmlString GetFileContent(this HtmlHelper helper, string fileName) { var file = helper.ViewContext.HttpContext.Server.MapPath(fileName); if (File.Exists(file)) { using (var stream = File.OpenRead(file)) using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var content = streamReader.ReadToEnd(); return new MvcHtmlString(content); } } throw new FileNotFoundException("Can't fine it", file); } public static MvcHtmlString IncludeHtml(this HtmlHelper htmlHelper, Uri url) { var htmlResourceService = ObjectFactory.GetInstance(); try { var content = htmlResourceService.GetHtml(url); return MvcHtmlString.Create(content); } catch { return MvcHtmlString.Empty; //return MvcHtmlString.Create(""); } } public static MvcHtmlString IncludeHtml(this HtmlHelper htmlHelper, string url) { var htmlResourceService = ObjectFactory.GetInstance(); try { var content = htmlResourceService.GetHtml(new Uri(url)); return MvcHtmlString.Create(content); } catch { return MvcHtmlString.Empty; //return MvcHtmlString.Create(""); } } } }