Display Paragraph with same format(With line Break) - c#

I store two paragraphs in sql server in same field. My Problem is while retrieving data from database and display in the report it display both paragraphs as single Paragraph. But while using TextArea it displays good. but Is there any options to display Paragraphs as i stored in HTML

It would be great if you provide what tag you have been using or just a code sample of your current project.
But this sounds like the paragraph is being displayed inline, possibly from span , i or no tags at all.
If you have no wrappers, wrap it inside <div> Quack! </div> or <p> Quack!</p>.
If you have existing wrappers and would like to keep them, set their css styling into display: block.
I guess this is the best I could answer without a slight clue of what the sample is.
Or if you are injecting results from the server, this would mean a different case and you will need to loop through the results and wrap each of them.

Related

How to generate a .pdf file by keeping the Bootstrap 4 layout using C# asp.net?

I'm looking for a solution, in C# Asp.net, allowing me to generate a .pdf file of detailed statistics (of a Partialview I created) while keeping the layout of Bootstrap as well and my personal CSS too. I tried to use Dinktopdf but apparently this library does not support Bootstrap 4 flexboxes and I end up with a totally distorted statistics table
I expect this kind of result
But the actual output is
As you can see, the right column content seems to be out of document.
This is true that there is no wacky CSS for this document but I would like to reuse it on another document with more CSS styles.
If any of you would have a solution to this problem or would have another bookstore (instead of DinkToPdf) to suggest me.
I have used this recently and found that the Bootstrap grid system worked well for this type of layout. here is what i used to get a split 2 column layout.
<div class='col-xs-6'>
"add content here"
</div>
<div class='col-xs-6'>
</div>
"add content here"
<div class='clearfix'></div>
the "clear fix" just ensures the next column div you add goes back to first column.
i also found that the HTML parsing of DinkToPDF is not great, make sure there are no extra spaces next <,>,= seems to confuse it.

Best way to format randomly copied texts from other websites?

Problem:
My site allows users to copy/paste contents from other files/documents like MS Word and websites (eg CNN.com) into the Rich TextEditor we provide. This Rick TextEditor supports (and we too have to support) paste contents with embedded styles, this brings random styles, tags inline styles from content origin.
Eg: If you paste from any MS word document, it brings H1, H2, P, UL/OL/LI, STRONG, I, EM, TABLE etc. with their own styles. Same happens when you copy paste from other webpages.
How To Format?
I am looking for THE best way to handle the formatting of these kinds of user-generated contents. First, I need to keep the copied tags intact. Lets say, H1 was brought from user from MS Word - I have to keep this yet style on my own using given corporate branding.
Another problem is, when you copy/paste from external origin - some tags are not properly closed - this causes my layout break. How do we handle this?
For styles, m applying
.article * {
allKnownCSSProperties: myValues!important;
}
Any method would work. JavaScript, C# is preferred.
To strip out unwanted styles a simple regex would suffice. In Javascript:
/( style=['"][^'"]*['"])/g
I'd try to solve problem with lack of closed tags as this:
Parse whole message and collect tags that's not ends with /> and remove them if you're find same tag starts with </. Exclude tags that may not to have close tag, generate close tags for all tags that still in collection and place them at the end of yours Rich TextEditor layout. It may not work in some cases or looks clumsy but that first that comes in mind and it may help to solve the problem

Retrieve text from database and format it on the front end of the website

I have some text currently stored in my database table as nvarchar.
I am currently retrieving the text using a stored procedure and binding it to a literal within a gridview on the front end.
What I would like to do is to retrieve the text and then format it , like inserting line spaces and making
certain area bold. Is it possible to do so ? Can anyone give me an idea of how it can be done ?
One idea thats striking me is to use XML while storing the text . But even if I do that how would I make a certain part of the text bold and include line spaces.
So currently, my text is stored in the database table column nvarchar(max) as:
This is the heading this is the content
What I would like to do is to display the above within a gridview like:
**This is a Heading** (heading in bold)
This is the content
The simplest method (one I have used several times) is to store the html in the table like this:
<h1>This is the heading</h1>This is the content
You will have to add special handling for working with html, but it works just fine.
You can also store the header string in one field, and body in another.
Short of that, you would have to have some indicator telling the front which part of the string should be bolded, etc. and that can get very complex
Short answer is that this is possible but takes some work.
You first need to decide in what format are you going to store the data and how can you specify format on the client side, before text is entered into database.
If you have WYSIWYG editor for text – html conversion you can try storing the HTML. This will be the easiest way in terms of storage.
If you decide to use this method note that you’ll need to do a lot of validation on the server to avoid cross site scripting attacks. Shortly put – make sure the HTML you get on the server doesn’t contain any javascript or any tags apart from those you want to support.
Its better to use Editor of AJAX Toolkit, doesnt required any other thing, its a complete editor, you can even color your font as u wanted.

How to tell height of paragraph in OpenXML?

I'm generating an MS Word document from user data. The data is placed in a container which is serialized to XML, and the resulting XML is converted to OpenXML using XSLT. There are a few minor changes done programmatically in C# to generate the Word document, as they can't be done with XSLT.
There is a user requirement that an item be placed completely on one page without any associated data being split onto another page. Sometimes one item will fill up an entire page, and sometimes I can fit three or four items on one page (I need to insert a separator (horizontal rule) between items that fit on the same page.)
Is there a way to determine whether or not one item or OpenXML paragraph will fit entirely on the "current" page? This can be either via C# or XSLT, and I can work something out.
Unfortunately, the only way this can be reliably done is to actually render the output, including all of the font sizes, bolding, kerning and all that. Which means you have to do the pagination in Word, and then save it back to the OpenXML.

HTML tags inside the Database - YAY or NAY?

I am using ASP.NET with C# and SQL Server 2005. I have a plane simple ASP.NET label on my form.
<asp:Label ID="lblBodyCopy1" runat="server"></asp:Label>
On Page load i populate this label with text that is saved in my database.
<p class="r_box_A">text text</p><p class="r_box_B">text text text</p>
Is this the right thing to do? If not what is then because i need to populate that label with text in such way that will have paragraphes and styles to each paragraph.
Thanks in advance!
Generally, no. You want your DB fields to be independant of the medium they'll be used in (because there may be many: HTML, Plain Text, etc)
What you should do is reformat your fields to whatever context they are being displayed. This implies that if you need the data in a 'richer' format, you typically use a markup scheme (markdown, perhaps) so you can process it and render it in whatever fashion you like.
You may, however, cache this formatting in another field, to speed up the retrieval process.
You can have HTML code in your Label as well as your Literal. A Literal control is much more light weight than a Label.. it's meant to write out text/html directly to the browser. A Label is little bulkier than a Literal, but has all benefits of a WebControl such as styling options etc.
Literal Control : Asp.NET Literal
Who enters these strings to the database? The usual problem with this approach is that:
you need to make sure that the resulting html is well formed
it can be not secure if people include scripts in the html stored in the database, etc.
So in most cases you want to store only real text in the database, and then format it and escape all html chars when adding to the page.
I personally would avoid storing the HTML in the database... but then again it depends on the context.
If you have a table designed for storing input from a rich textbox then you will somehow need to store any formatting that has been applied.
As others have mentioned, prehaps a safer alternative would be to create your own [bbCode] syntax, pretty much similar to the way the textbox on here (Stack OverFlow) works...
eg. any text in bold 'foo'
becomes [b]foo[/b]
There is added work involved because you will need to parse the text and replace any tags with the equivalent [bbCode] tags and then do the reverse when outputting to a web page, but I personally think it is a safer approach with regards to data integrity.
Why not store it as xhtml in the database - you can validate it before you push it in. use the XML field type. This way if your need to query on it you can, and you data is still structured.

Categories

Resources