Reading only a small part of a big file into a string for analysis

Hi,

We are currently automating a process where we have emails sent to a ticketing system as attachments, in .eml files. Part of the process is to check whether the sender (of the email in the file) is from a particular domain. We have it all figured out and it works (reading the eml as a txt file with ReadTextFile, and then checking the content with IsMatch).

The problem is when the email has a big attachment, it takes a lot of time to read it into a string - it can literally take minutes.
So my question would be - do you know of any simple way to read just a first x kilobytes of a file, or possibly read it line by line? I cannot seem find any good way to do this, and would rather not dig myself into building my own workaround.

I would appreciate any direction.

Cheers
Andrzej

1 Like

Hi @Andrzej_Kinastowski,
Welcome to the Community!
Have you tried to use only reference to mail body in your workflow?

@Andrzej_Kinastowski
If you are using File.ReadAllLines you should switch to File.ReadLines. The former reads every line of the file, which is not necessary here. File.ReadLines reads a file one line at a time, so it is quicker for large files where you can stop reading the file once the keyword is found.

Ahh, i missed this somehow. This helps, many thanks :slight_smile:

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.