Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm creating a form in asp.net (Visual Studio 2003), the form then will be used to generate a CrystalReport (Crystal Report XI) by using CrystalReportViewer.

The form is quite simple that used to stored data in database, I'm using multiline textbox in the form. I also using the following code to replace the newline in the textbox into html <br> tag
C#
.Replace(Environment.NewLine, "<br>")


The code is working fine, the newline is changed into <br> in the database. Then I need to fetch the stored data back into the form for editing purpose. I then use the following code to replace the <br> back into a newline in the textbox.
C#
.Replace("<br>", Environment.NewLine)


Then I generate the CrystalReport in the asp page. It's successfully generated, the problem occurs when I try to export the report. It doesn't pop out an export window as it has to be, it returns an Unterminated string constant error message.

I then tried to change the code that used to replace the <br> into something like the following
C#
.Replace("<br>", " ")

And the export function is working fine, so I think the problem is related to the Environment.Newline. But I was having a very hard time finding another way to replace the <br> tag except by using the Environment.Newline in the ASP. Do you guys can help me dealing with this issue ?
Posted
Comments
Sergey Alexandrovich Kryukov 13-Jan-12 4:42am    
Just one note: correct HTML break tag is <br/>, not <br>. I'm not sure if it can help you, but it's much better to keep HTML a well-formed XML.
--SA
_andha 17-Jan-12 2:58am    
thx for that, i've changed it. tho' it's not solving the problem.

I've been working on this for days, and assuming that the problem lies on the Crystal Report exporting process. The Crystal Report couldn't export the report if the Crystal Report Viewer is in the same page with a form that contain a textarea with multiline value in it.

I've tried to use a lot of Newline replacement methods including the SQL Replace function but none of them could solve the problem.

Finally I decided to show the report and put the Crystal Report Viewer in a separated page, and things are now going back to work.

I would like to thank you for your help and responses, I really appreciate that.


 
Share this answer
 
I'm not sure what your Environment.NewLine is returning (maybe something weird because of your regional settings ?!)

Try a workaround, replacing Environment.NewLine with "\r\n" or just "\n"
 
Share this answer
 
v2
Comments
_andha 13-Jan-12 3:35am    
I've tried to use the \r\n or \n instead of Environment.Newline, but I still got the same error. Regarding to the regional settings, where could I find it ? Thx.
HaBiX 13-Jan-12 3:47am    
Regional settings usually change decimal number characters, date formats, etc etc (possibly even Envioroment.NewLine). But if "\r\n" didnt help neither will regional settings (you can find them in control panel).

I'm guessing you have bug somewhere else:

- make a simple test table in database (1 varchar column)
- from .net insert string "test\r\ntest" into db (no replacing)
- create a new simple report with 1 filed (can grow), with datasource pointing to test table
- view report / export



- if the trouble is still there, there is a problem with your current crystal reports version (did you try some other version of VS/CR?)
- if the trouble is gone, you may have a typo somewhere in your replacing logic (from and to db)
_andha 17-Jan-12 3:00am    
well. i've tried it, but still couldn't figure out the root of the problem. i'm thinking to do the replacement in the HTML code, do you know whether is it possible or not ?
HaBiX 17-Jan-12 3:26am    
character replacement is possible in html with the help of javascript:

function test(stringIn) {
return stringIn.replace('W', 'H');
}
alert(test('Wello world'));
Sergey Alexandrovich Kryukov 13-Jan-12 4:40am    
What you suggest won't change anything except loosing system compatibility. Why making a statement without testing the case? You would see that Environment.NewLine returns correct new line for the system.
--SA

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