Showing posts with label Crystal Reports. Show all posts
Showing posts with label Crystal Reports. Show all posts

Tuesday, June 21, 2011

Crystal Reports filed text newline, carriage return, \r\n

Nel mio crystal report ho un textFiled, vorrei settare il suo valore runtime.

rpt.DataDefinition.FormulaFields["fieldTarga"].Text =TextBoxTarga.Text;
Tutto funziona correttamente, fino a quando il valore da assegnare non contiene i caratteri speciali linefeed e carriage return "\r\n". Questo è un bug di Crystal Report for .NET 
Per risolvere il problema, anche se di primo acchito appare insensato, possiamo ovviare usando questa semplice funzione:
string FormatCRField(string s)
        {
            return "'" + s.Replace("\r\n", "' + chr(10) + '") + "'";
        }
Sostituisce "\r\n"  con chr(10) che verrà interpetato correttamente dal "parser" di CR.
Spero che questo possa aiutarti.