Solved

Retaining format from multiline textboxes into email

Posted on 2007-04-10
3
222 Views
Last Modified: 2010-04-15
ASP.Net 1.1 (not 2.0)
C# on Windows server & IIS

I have an ASP.Net application (contact page)
User chooses whom they wish to cotact from a short list of names with check boxes.
They then fill in a subject line, write a message (stringbuilder) in a multiline text box, click send and an email is generated and sent to each of the selected users.  Simple.

All works fine, except the message body appears as a single string.  
For example :
********************************
Here is text as it would appear in the text box as the user is typing their message.
Here is the next line
And another line break here for line number three, followed by a couple of spaces

then a thanks and
the useres name
*************************

However, when it goes from the app to the email, it all becomes a single line, like this

-----------------------
Here is text as it would appear in the text box as the user is typing their message.  Here is the next line And another line break here for line number three, followed by a couple of spaces then a thanks and the useres name
-----------------------


What do I need to do/use in order to get the retain the formatting (complete with line breaks) from the app to the email???

Thanks!
0
Comment
Question by:nbbit
3 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 500 total points
ID: 18884926
string s = "Here is text as it would appear in the text box as the user is typing their message.
Here is the next line
And another line break here for line number three, followed by a couple of spaces

then a thanks and
the useres name
"

s.Replace("\n", "<br>")
0
 
LVL 10

Expert Comment

by:MrClyfar
ID: 18885008
Hi there.

A quick look indicates to me that it could be the carriage return and line feed characters are missing from the email text when it get's emailed. When the text is added to the stringbuilder, you must take into account the ControlChars.CrLf characters.

In the routine you have for adding text to the stringbuilder, you should have a line that adds the ControlsChars.CrLf character pair into the stringbuilder. Then, when you do a ToString, those characters should allow you to format the text as it appears when the user wrote it.

You may have to do the append like this:

Append("" & ControlChars.CrLf)

since if you do Append(ControlChars.CrLf) then you might get an exception of incorrect argument type.

Try it and experiment with the code. Hope this helps.
Jas.
0
 

Author Comment

by:nbbit
ID: 18897579
First answer gets the prize.  
Thanks for your help lem - as soon as I saw it I was like "DUH! I knew that!"
Thanks for input MrClyfar.

Be well all!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question