I have some HTML text files that I would like to dynamically include in an ASP.NET page.
What is the best way to do this?
My first guess was to create a Literal control on the page and output as follows:
litMyLiteral.Text = System.IO.File.ReadAllText("c:\path\to\file.htm");
Is this a good solution, or is there a better one? For me, performance is a primary goal since these snippet files are output on every page on my site and there’s a lot of traffic.
Thanks
Depending on how many files you have or how often you have to read them, I would suggest dynamically loading into the asp.net cache AS you need them and having some type of expiry or the cache.
Write some type of class to wrap you file access and caching implementaton. This code will probably work but don’t use it as is, it’s just to give you an idea of what I am talking about. Please not all the comments for improvements.
You should consider your cache expiry and see what would best suit your data. You could also implement some type of max check to allow a maximum number of cached files so the memory foot print doesn’t get to big if you expiry is long. You really need to look at your total number of files and their size and figure out what would best suit your needs.