Click here to Skip to main content
15,441,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to "display" my .html file on my web page using literal. To be honest I make it work using iframe but the only reason I'm not going to use iframe is that every time it loads my .html file, the iframe tends to have scroll and borders and gray background. I thought I can fix it by using formborder or formBorder set to 0, scroll="non" and set it's background-color to white but unfortunately, none of it worked. All I wanted to do is to display my .html on my web page without these borders, scrolls and unchanged background color. I read some articles that I can use asp.net control literal to display my .html file but all of them didn't showed the process on how to do so.

I'll be pleased and grateful to you if you could make some suggestion/s or solution/s to my problem.

Cheers~

Note: my sample.html is a document converted from sample.rtf. I thought I can display a .html to my page.

What I have tried:

On My Server

Note: I want to keep my code from behind since I'll be filling the literal soon with the path coming from my database and I want my string file_location to catch that before passing it on literal control.

protected void Page_Load(object sender, EventArgs e)
        {
           string file_location = "Contents/sample.html";
        }


On my Client

<asp:Literal ID="display_html" runat="server"></asp:Literal>
Posted
Updated 1-Mar-18 12:24pm
v5
Comments
F-ES Sitecore 1-Mar-18 6:20am     CRLF
This will only be possible if whatever is in your html file is valid when injected into your page. If your html file is a complete working html file then it's not going to work as you're going to end up with nested html elements. Not only will the html have to be valid when nested in your page, but the styles will aswell as the html will inherit the styles of the page it is injected into. That is why people use iframes for this as it solves all these issues. So the answer to if this is possible depends on what is in your html file.
Green Blanket 1-Mar-18 18:22pm    
my sample.html is a document converted from sample.rtf. I thought I can display a .html to my page.

Try This:

public void bindDischargeContent()
        {
            string urlAddress = "Your Daynamic URL";// System.Configuration.ConfigurationManager.AppSettings["DisChargeSiteUrl"];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;
                if (response.CharacterSet == null)
                {
                    readStream = new StreamReader(receiveStream);
                }
                else
                {
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                }
                string data = readStream.ReadToEnd();                
                LitForOtherWebsite.Text = data;
                response.Close();
                readStream.Close();
            }
        }



HTML Part:
<asp:Literal ID="LitForOtherWebsite" runat="server"></asp:Literal>

Please vote!!
 
Share this answer
 
v2
Comments
Richard Deeming 1-Mar-18 13:42pm    
An HTTP request just to read a file that's on the same server? That's a bit over the top, don't you think?
Green Blanket 1-Mar-18 18:22pm    
my sample.html is a document converted from sample.rtf. I thought I can display a .html to my page.
Try:
C#
const string virtualPath = "~/Contents/sample.html";
string physicalPath = Server.MapPath(virtualPath);
display_html.Text = System.IO.File.ReadAllText(physicalPath);

But do bear in mind the comment from F-ES Sitecore: if the file you're loading is a complete document, rather than an HTML fragment, then you're going to run into issues.

If you just want to remove the borders from the iframe, you can do that:
HTML
<style>
iframe.seamless {
    background-color: transparent;
    border: 0px none transparent;
    padding: 0px;
    overflow: hidden;
}
</style>

<iframe class="seamless" frameborder="0" allowtransparency="true" scrolling="no" src="Contents/sample.html"></iframe>

HTML5 iFrame Seamless Attribute - Stack Overflow[^]
 
Share this answer
 
Comments
Green Blanket 1-Mar-18 18:22pm    
my sample.html is a document converted from sample.rtf. I thought I can display a .html to my page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900