Solved

Retaining format from multiline textboxes into email

Posted on 2007-04-10
3
219 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 17

Accepted Solution

by:
lem2802 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now