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 5969643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:15:34+00:00 2026-05-22T20:15:34+00:00

I am trying to get the content from an attachment on an email. I

  • 0

I am trying to get the content from an attachment on an email. I am able to read the email and all of its attributes. The attachment is a text file (.txt). How would i grab the actually text content of the attachment? Below is a section of my code showing how i grab each email and then get its attributes and store them in the findResults list. Something like fileAttachment.Name would give me the name of the attachment. fileAttachment.content.tostring() will only show me system.Byte[].

FindItemsResults<Item> findResults = service.FindItems(fid1, new ItemView(int.MaxValue));
service.LoadPropertiesForItems(from Item item in findResults select item, PropertySet.FirstClassProperties);

foreach (Item item in findResults)
{
    String body = "";
    #region attachments
    if (ReadAttachments == "1")
    {
        EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));

        foreach (Attachment attachment in message.Attachments)
        {
            if (attachment is FileAttachment)
            {
                FileAttachment fileAttachment = attachment as FileAttachment;

                // Load the file attachment into memory and print out its file name.
                fileAttachment.Load();

                String attachbody = fileAttachment.Content.ToString();

                if (attachbody.Length > 8000)
                {
                    attachbody = attachbody.Substring(0, 8000);
                }
                Console.writeline(attachbody);
                #endregion

            }
        }
    }
    #endregion
}   
  • 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-22T20:15:35+00:00Added an answer on May 22, 2026 at 8:15 pm

    That’s because it is an array of bytes you’ll have to use a StreamReader to get it

    var stream = new System.IO.MemoryStream(fileAttachment.Content);
    var reader = new System.IO.StreamReader(stream, UTF8Encoding.UTF8);
    var text = reader.ReadToEnd();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the content from all the nodes in the bookmarks menu
I'm trying to create a file dynamically in Django: response = HttpResponse(mimetype='text/txt') response['Content-Disposition'] =
I'm trying to get content from an RSS2 feed from one of my sites
I trying to get the content of a text document with the google docs
I am trying to get file content in bytes in Android application. I have
So here is my problem, I'm trying to get the content of a text
I'm trying to send an encrypted email with an attachment from PHP, however, my
I am trying get content from the link https://....com:8455 where Server's certificate is not
I'm trying to stream the file from file system to browser and cant get
I am trying to get an uploaded file to be sent as an attachment

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.