Question

I have a DecXpress report and the datasource shows a filed where the data is comming something like

PRODUCT - APPLE<BR/>ITEM NUMBER - 23454</BR>LOT NUMBER 3343 <BR/>

Now that is how it is showing in a cell, so i decided to decoded, but nothing is working, i tried HttpUtility.HtmlDecode and here i am trying WebUtility.HtmlDecode.

   private void xrTableCell9_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
    XRTableCell cell = sender as XRTableCell;
    string _description = WebUtility.HtmlDecode(Convert.ToString(GetCurrentColumnValue("Description")));
    cell.Text = _description;

}

How can I decode the value of this column in the datasource?.

Thank you

Was it helpful?

Solution

If you need to show the description with the < /> also, you need to use HtmlEncode.


If you need to extract the text from that html

public static string ExtractTextFromHtml(this string text)
        {
            if (String.IsNullOrEmpty(text))
                return text;
            var sb = new StringBuilder();
            var doc = new HtmlDocument();
            doc.LoadHtml(text);
            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//text()"))
            {
                if (!String.IsNullOrWhiteSpace(node.InnerText))
                    sb.Append(HtmlEntity.DeEntitize(node.InnerText.Trim()) + " ");
            }
            return sb.ToString();
        }

And you need HtmlAgilityPack


To remove the br tags:

var str = Convert.ToString(GetCurrentColumnValue("Description"));
Regex.Replace(str,  @"</?\s?br\s?/?>", System.Environment.NewLine, RegexOptions.IgnoreCase);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top