0

I'm trying to find out what my options are to inject a local html file's contents into a webpage. I have a Scheduled task that gets a list of .html files from a remote server and stores them on the local webserver, this I can't change.

How can I get the .html file injected into a webpage via code-behind? I have a Literal control on the page I can put the HTML in but whats the best way to get the html from the file? Filestream? Or put those files containing partial HTML into IIS and serve them somehow?

From my understanding of my requirements I can't use ajax or an iframe. Sooo ?

MisterIsaak
  • 3,882
  • 6
  • 32
  • 55
  • 1
    I hope you have permission to copy those files, and you're not just scraping content from someone else's website? :) Also, are you *really* still using ASP.NET 1.1? – Richard Deeming Nov 30 '12 at 18:11
  • Ha, yes I have permission. Its a service from another company that generates specific html for each one of our products. They don't host anything, just give us a zip file containing the html files. So in the zip file i may or may not have a html file from them that I have to inject into a corresponding product page. And yea .net 1.1 will be the death of me. – MisterIsaak Nov 30 '12 at 18:31

2 Answers2

1

I think you need to parse the downloaded HTML file and get the part you want and then use Literal on the hosting webpage. You need to write a code in the code behind, by opening the corresponding file from the local directory, parse it if you need to and then set it like literal = htmlContent. It needs to happen during page load or you create a static page and do the injection before hand.

iefpw
  • 6,816
  • 15
  • 55
  • 79
  • I was leaning towards this but was concerned about reading a file every time a product's page is loaded. Seemed like a bit of a bottle neck? I was hoping there was another option but it doesn't look like it i guess. – MisterIsaak Nov 30 '12 at 18:32
  • @Jisaak: I'd be inclined to move the parsing part to the scheduled task, so that the page just needs to include the entire file. If you can get .NET 2.0 on the server, you'll be able to use the HtmlAgilityPack for this: http://htmlagilitypack.codeplex.com/releases/view/90925 – Richard Deeming Nov 30 '12 at 18:37
  • Other option might be during the scheduled task, parse the content and save it in a database or create a static files every time. Pull from database like how most sites does. In terms of speed, I would do save, parse and save to database at the same time. 2. pull from database when the page is pulled. A lot of work needs to be done beforehand I think. – iefpw Nov 30 '12 at 18:40
  • Each html file only contains html that i need so I don't think I'll have to parse anything (its just a `div` with inner html). I guess I can put everything in the database table as well if performance becomes an issue. There's 0% chance I can upgrade .net. :( – MisterIsaak Nov 30 '12 at 18:53
  • 1
    You need to inject the HTML either way. I would use database or do dynamic injection by locating the file from the directory (on the local server) or use sql server. If there are a lot of files in the directory, you website will get slow, so therefore in my opinion database with a specific id with an index will be fast. Either way I think it is an awkward way to do. – iefpw Nov 30 '12 at 18:55
  • Well, I made a fancy DTS package to ftp to the files, unzip, store in database. Appeared to be working great until I found out some of the html files are greater than 8k. And of course since I'm working with .net 1.1 I'm using SQL 2000 with no `varchar(MAX)`... Looks like I'm stuck with the file system from what I can see. Thanks for all the help and advice! – MisterIsaak Nov 30 '12 at 21:24
  • 1
    @Jisaak: Can't you use `text` / `ntext` instead? – Richard Deeming Nov 30 '12 at 21:45
0

Can you make the .html files available on the same local web server? If you can do this, then using Jquery you can load this .html file.

$('#loader').load('www.mywebserver.com/htmlrepository/test.html');

'loader' above is the id of the html element where the html file content is to be loaded. 'test.html' is the html file downloaded.

Check more on this here

David Jiboye
  • 511
  • 8
  • 19