Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7420833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:18:27+00:00 2026-05-29T08:18:27+00:00

I have a plain text file that I need to read in using C#,

  • 0

I have a plain text file that I need to read in using C#, manipulate it a bit then I need to email it. That’s easy enough, but it also has to stay in the same format as it’s original state:

This is an excerpt from a sample file “mySample.txt”:

   *****************************NB!!!!**********************************
   *Please view http://www.sdfsdf.comsdfsdfsdf  .                      *
   *********************************************************************


        *** DO NOT DELETE or ALTER ANY OF THE FOLLOWING TEXT ***

                          Company X PTY.
                    Lorem Ipsum Office
                  Last Change - 01 February 2008

           APPLICATION TO ESTABLISH A COMMUNITY WITHIN
                THE RESTIN DISTRICT OF THE IPSUM.

    ===================================================================

    1. COMMUNITY and ACTION

    Give the name of the community.  This is the name that will be
    used in tables and lists associating the community with the name
    district and community forum.  The community names that are
    delegated by Lorem are at the district level
    The Action field specifies whether this is a 'N'ew application, an
    'U'pdate or a 'R' removal.

    1a. Complete community name:**{0}**
    1b. Action - [N]ew, [U]pdate, or [R]emoval :**{1}**

As you can see I’ve got place holders {0} and {1} in the file which is to be replaced by an automated process.

In my C# I’m using a stream reader to read the entire file into a StringBuilder object then replacing the place holders using the StringBuilder.AppendFormat method.

The problem is when I add the text to a email message body and send it the format ends up looking different. It looks like a bunch of spaces or tabs get removed in the process.

private void Submit_Click(object sender, EventArgs e)
    {
        //create mail client
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.To.Add(ConfigurationManager.AppSettings["SubmitToEmail"]);
        message.Bcc.Add("xyz@test.com");
        message.Subject = "Test Subject";

        message.BodyEncoding = Encoding.ASCII;
        message.IsBodyHtml = false;
        message.Body = _PopulateForm(_GatherInput());//calls method to read the file and replace values
        client.Send(message);

        //cleanup
        client = null;
        message.Dispose();
        message = null;

    }

Anyone have any ideas on how to keep the formatting in tact?

Thanks,
Jacques

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:18:28+00:00Added an answer on May 29, 2026 at 8:18 am

    The answer seems to have been with .net and the Mail message object. Instead of adding the content to the Body property, you have to create an alternateView object and add it to that. That solved my problem.

    Regards,
    Jacques

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that generates a plain text file. The structure (layout) is
I have a plain text file looking like this: some text containing line breaks
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
We are currently storing plain text passwords for a web app that we have.
I have about 40000 records in that table that contains plain text and within
I have an Android app that saves a text file directly onto the phone,
I am using a plain text file in a PhP script. Is there any
I need a plain text representation of an arbitrary HTML file (e.g., a blog
I am writing an application that must generate a plain text file with fixed-sized
I have a plain text file which have the list of countries as follows.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.