Why doesn't my RDLC data display HTML content properly? - c#

Why doesn't my RDLC display the HTML content? I have saved encoded HTML formatted text in an Nvarchar field in the sql table like given below:
<p><strong>ANDSLASKNDKLSNALNDKLANDLANND</strong></p><pre><pre lang="c#">
Even in RDLC, I have checked the HTML- Interpret HTML tags as style option but still it doesn't display the formatted output.
Why?

As discussed in comments, only subsets of HTML can be rendered (to protect it from html injection). Instead of using <strong> you will have to use <B> to define bold text.
When you import text that contains HTML markup, the data must always
be parsed by the text box first. Because only a subset of HTML tags is
supported, the HTML that is shown in the rendered report may differ
from your original HTML.
The following is a complete list of tags that
will render as HTML when defined as placeholder text:
Hyperlinks: <A href>
Fonts: <FONT>
Header, style and block elements: <H{n}>, <DIV>, <SPAN>,<P>, <DIV>, <LI>, <HN>
Text format: <B>, <I>, <U>, <S>
List handling: <OL>, <UL>, <LI>
Taken from this: http://msdn.microsoft.com/en-us/library/cc645967.aspx

Related

Display html text from database in pdf generated with iTextSharp (Asp.Net Webform)

I have a problem to properly display an html text from database in pdf document which is generated with iTextSharp. I have a text editor in my project and my text is written to the database in this format (example)
<i><b>Hello World</b></i><br><p>What a <font color="#330022"> wonderful day!</p>
When I pass this text to the pdf document is displayed with the tags. I don't know how to get rid of them and actually pass the bold and italic text or the color. I have found only a solution for the <br> tag like this
pdf.PreviewText = get.Rows[0]["text"].ToString();
previewText = previewText.Replace("<br>", "\n\r");
for the <b> tag I have tried previewText = previewText.Replace("<b>", ""\x1B|"); but it did not work for me. If anyone has an idea how can I replace these tags with escape characters which would work in c# I would be very grateful.

Merge Rich Text ( HTML ) to Word Document Content Control using Open XML

I have a word template which has a content control placeholder to hold rich text data. The data comes from a sharepoint list (rich text field) and may also include tables in it.
On checking the data from sharepoint list I found it returns me a HTML formatted data. I wish to place this data in the content placeholder with proper formatting.
For example if the data returned is HTML table ( format) I want a table to be created with data populated. Is there any method available to place the data in content control.
I found that third party tool converter at http://html2openxml.codeplex.com/ which is available for conversion, however this appends data to MainDocumentPart not to content control.
Please guide. Thanks in advance.
You could try to use WordDocGenerator, which uses content controls. Then combine it with html2openxml, as discussed here. However, I find the formatting in some cases becomes terrible after adding the html content into your content control--one example is when inserting lists, the bullet points goes out of view when you open the document. I have not tried adding a whole table into a content control.

Bootstrap Wysiwyg Editor: Saved Data in HTML to Database, trying to send the HTML back to the editor in richtextbox format

So, I have the rich text box editor from Bootstrap-Wysiwyg.
If the textbox contains:
This is a bold statement.
Then my DB will save the text as:
(using a hidden tab where I insert the editor.html())
<b>This is a bold statement.<b>
If I save the file again, the RTF will convert it to:
<b>This is a bold statement.<b>
When I put the this text back into the editor using a Model.Value, it does not convert it to rich text but instead keeps the text as though it were a string and states it exactly as it is saved in the DB.
How can I convert the text in my model to show up in the rich text editors format?
I've been searching the net quite a bit, and most functionality refers to files. This is a new subject to me, so any insight is appreciated on how to fix this. (Editing text without formatting is obnoxious!) Thanks in advance!
Just in case someone else gets stuck, I was able to resolve this issue by doing the following:
I created a hidden div (which I populate first with my Model):
<textarea style="display: none;" id="editorCopy" name="body">#Model.Body</textarea>
and left my editor div empty:
<div id="editor" contenteditable="true">
</div>
and in my JQuery:
I set my editors text to my hidden divs value, and on submit, I replace the hidden div with my editor text:
$('#editor').html($('#editorCopy').val());
$('#postSubmit').click(function () {
$('#editorCopy').val($('#editor').html());
});
This allowed my rich text to show on edit. There might be a better solution, but at least this works! :]

How to bind html to an rdlc file

I have text stored in a column of a table within my database, with html tags .
Example :
<table><tr><td> hello </td></tr></table>
I am binding the text to the website and it works perfectly. It gets displayed as
hello
on the website.
Now I would like to create a rdlc report and am binding the same dataset to the report.
But I see :
<table><tr><td> hello </td></tr></table>
on the report instead of
hello
I think I understand why this is happenning , because the rdlc file cannot render html. But is there a way
that I can see "hello" on the website. ? Please let me know if you know of any other way to do it .
you can render using HTML tags in RDL as follows :
Left click the field you want to display so that the <Expr> tag is highlighted
Right click the highlighted <Expr> tag and choose Placeholder Properties...
On the General tab, select the HTML- Interpret HTML tags as style radio button

Insert html tag to a Database as a String and retrieve it back in C#

I want to insert html tag to a Database as a String and retrieve it back. after retrieved it ,I want to bind it in Grid.
as a example
String word = "<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab";
after I bind to the grid it should be
This is Heading(in a big font size)
This is body(in small font) - (tab space) This after tab
However this way is not working. It shows
<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab
word instead of applying real HTML behavior. I tryout with '\' special character removal but it remain same result.
Please help me.
Exactly which control are you using? Most of them will escape html like that for you, and to get it to be written 'as-is' you have to set a property.
If you're using GridView, then you can set the HtmlEncode on your BoundColumn to false.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx
If you're using AutoGenerateColumns, see this SO thread: Prevent HTML encoding in auto-generated GridView columns
Saving into DB is not a problem, you can save directly the string into DB,But when displaying on UI you must use HttpUyility.HtmlEncode(), else it will invite Javascript Hacking.
But if you are entering data from WebPage, make sure Input Validations are turned off Else you will get XSS script attack error.
you can bind your text in literal control it will represent the actual HTML formatted text.
like :
ltrlMsg.Text="<div class=\"Message Success\"> Your Message has been sent successfully! </div>"
or you can bind in you grid too.

Categories

Resources