Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET New Line Character 2

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
VB.NET New Line Character does not work for me. everything is in one line.

Code:
If rcvdEmail = "tareee@yahoo.com" Then
            sMsg = "Vendor Registration form has been recieved." & vbCrLf & "The results are as follows:" & vbCrLf & vbCrLf
            sMsg += "Vendor Type : " & ckPrime.Text & " / " & ckSub.Text & " / " & ckDBE.Text & ControlChars.NewLine
            sMsg += "Federal Tax Id Number : " & txtFedNumber.Text & ControlChars.NewLine
            sMsg += "State Tax Id Number : " & txtStateNumber.Text & ControlChars.NewLine
            sMsg += "Full Legal Contractor / Vendor Name  : " & txtLegalName.Text & ControlChars.NewLine
            sMsg += "Doing Business As Name (DBA) : " & txtBusiness.Text & vbCrLf
            sMsg += "Street Address 1 : " & txtStree1.Text & vbCrLf
            sMsg += "Street Address 2 : " & txtStree2.Text & vbCrLf
            sMsg += "Company Email Address: " & txtEmail.Text & vbCrLf
            sMsg += "City : " & txtCity.Text & vbCrLf
            sMsg += "State : " & txtState.Text & vbCrLf
 
use StringBuilder instead of +=. This will manage memory more efficiently.
Depending on what you are using this string for will determine why you are not getting the desired results.
If you are placing this text on a webpage, then you need to use HTML tags, not NewLine. either <br />, <div></div> or <p></p> will work.
If this is the the body of a MailMessage set IsBodyHtml = false. Otherwise you need to use HTML, not Newlines to break to the next line.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Hi Jason,

thank you for your reply.

The line break still does not work. can you help me if i am missing something here.

Code:
 Private Sub SendMail(ByVal toEmail As String, ByVal fromEmail As String)
        Dim strMsg As StringBuilder
        strMsg = New StringBuilder

        Dim objEmail As New MailMessage
        objEmail.To.Add(toEmail)
        objEmail.CC.Add(toEmail)
        'objEmail.Bcc.Add("faddis75@yahoo.com")
        objEmail.From = New MailAddress(fromEmail)

        Dim rcvdEmail As String = toEmail
        If rcvdEmail = "faddis76@yahoo.com" Then
            With strMsg
                .Append("Vendor Registration form has been recieved." & vbCrLf & "The results are as follows:" & vbCrLf & vbCrLf)
                .Append("Vendor Type : " & ckPrime.Text & " / " & ckSub.Text & " / " & ckDBE.Text & vbCrLf)
                .Append("Federal Tax Id Number : " & txtFedNumber.Text & vbCrLf)
                .Append("State Tax Id Number : " & txtStateNumber.Text & vbCrLf)
                .Append("Full Legal Contractor / Vendor Name  : " & txtLegalName.Text & vbCrLf)
                .Append("Doing Business As Name (DBA) : " & txtBusiness.Text & vbCrLf)
                .Append("Street Address 1 : " & txtStree1.Text & vbCrLf)
                .Append("Street Address 2 : " & txtStree2.Text & vbCrLf)
                .Append("Company Email Address: " & txtEmail.Text & vbCrLf)
                .Append("City : " & txtCity.Text & vbCrLf)
                .Append("State : " & txtState.Text & vbCrLf)
                .Append("Zip Code : " & txtZip.Text & vbCrLf)
                .Append("Fax Number : " & txtFax.Text & vbCrLf)
                .Append("Phone Number : " & txtPhone.Text & vbCrLf)
                .Append("Submitted By : " & txtSubmittBy.Text & vbCrLf)

                objEmail.Subject = "Vendor Registration"
                ' objEmail.Attachments.Add(New Attachment(AttachementFile.PostedFile.InputStream, AttachementFile.FileName))
                objEmail.Body = strMsg.ToString
                objEmail.IsBodyHtml = False
            End With

        Else
            With strMsg
                .Append("Hello, this is an automated message to let" & vbCrLf)
                .Append("you know that your request for vendor update has been received." & vbCrLf)
                .Append("We will take aproperiate action and  respond to you soon as possible." & vbCrLf)
                .Append("Thank you," & vbCrLf)
                .Append("Vendor registration ")
            End With
            If rdNewVendor.Checked Then
                objEmail.Subject = "Vendor Registration"
            Else
                objEmail.Subject = "Vendor Information Update"
            End If
        End If
      
        objEmail.Body = strMsg.ToString
        Dim SmtpMail As New SmtpClient()
        SmtpMail.Send(objEmail)
    End Sub
 
I thought i posted a reply, either the site is heavily caching, or I forgot to post.

use AppendLine, not vbCrLf example
Code:
.AppendLine(string.Format("Vendor Registration form has been recieved."))
.AppendLine(string.Format("The results are as follows:"))
.AppendLine(string.Format("Vendor Type : {0}/{1}/{2}", ckPrime.Text, ckSub.Text, ckDBE.Text))
.AppendLine(string.Format("Federal Tax Id Number : {0}", txtFedNumber.Text))
.AppendLine(string.Format("State Tax Id Number : {0}", txtStateNumber.Text))
.AppendLine(string.Format("Full Legal Contractor / Vendor Name  : {0}", txtLegalName.Text))
.AppendLine(string.Format("Doing Business As Name (DBA) : {0}", txtBusiness.Text))
.AppendLine(string.Format("Street Address 1 : {0}", txtStree1.Text))
.AppendLine(string.Format("Street Address 2 : {0}", txtStree2.Text))
.AppendLine(string.Format("Company Email Address: {0}", txtEmail.Text))
.AppendLine(string.Format("City : {0}", txtCity.Text))
.AppendLine(string.Format("State : {0}", txtState.Text))
.AppendLine(string.Format("Zip Code : {0}", txtZip.Text))
.AppendLine(string.Format("Fax Number : {0}", txtFax.Text))
.AppendLine(string.Format("Phone Number : {0}", txtPhone.Text))
.AppendLine(string.Format("Submitted By : {0}", txtSubmittBy.Text))

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Jason I really appreciate your help on this. I reformat the code using your code but i am still not getting the right result.when i receive the email i would like every fileld to start with a new line and that is not what i am getting here

Vendor Registration form has been recieved.
The results are as follows:
Vendor Type : Prime Contractor/Sub Contractor/DBE Federal Tax Id Number : 123 State Tax Id Number : 456 Full Legal Contractor / Vendor Name : Lunda Construction Doing Business As Name (DBA) : Lunda Street Address 1 : 123 st. paul Street Address 2 : 123 st. paul Company Email Address: faddis75@yahoo.com City : farmington State : IN Zip Code : 000000 Fax Number : 12345678 Phone Number : 12345678 Submitted By : Joe

 
try this, log the message body to a text file and check the formatting of the message log. if the message is logged in the correct formatting the email system is the problem, not the code. If the message is not logged correctly the problem is the code.

I know Outlook will remove "extraneous" line breaks in text messages. This would be the first thing I check after logging the message to a text file. If that's the case the actual email is formatted correctly. the problem is how the email client is interpreting the email.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Good point by Jason. The new outlook 2007 I know is quriky with HTML display as well. I know you are not foratting yours as HTML, but the point is, it may be outlook that is the problem.
 
Thank you Jason. I logged the message body to a text file and check the formatting of the message log and it is formatted correctly.It looks like the issue is with outlook.
is there any fix for that or I am out luck?
 
jbenson001 I am not sure if understand your suggestion. can you show me how I can start converting this to HTML
 
You can just use <div> tags. A div is a block element so the next item will occur on the next line.
Just simple format the email using HTML as you would layout any page.
 
can you show me how I can start converting this to HTML
not to sound rude, or pretentious, but you are designing a web application (at least that's the assumption posting on the asp.net forum). knowing HTML should be inherent. If not I would start here.

the only difference for the mail message is IsBodyHtml = true; instead of false.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
It was just a misunderstanding and I thought it was something other than changing IsBodyHtml to true. I know enough html and I feel comfortable with that. anyways, thank you for your help and time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top