How to Read from Notepad file


#1

Hi
I have 5 lines in notepad file [file.txt]:
eg.
Resources
Video
Documents
Help
ContactUs

I want to fetch the line’s text one by one, and save it in variable.

I am using:

  1. Select file Activity to select the file at run time [file.txt].
  2. Then Assign Activity and assigning variable of String type = File.ReadAllText(selectedFile).
    opList = File.ReadAllText(selectedFile)
  3. Then used For each loop

But no luck
Attached the file2nd-copy.xaml (8.1 KB)


#2

HI @shruti.o.gupta,

you can use Read Text File Activity, it will return the String value.

after getting the value using split Environment.NewLine option spit the value to array
For loop through the array value you can get the each value.

arrvalue= strvalue.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)

Regards,
Arivu


How to get the value of a variable from a txt file
#3

@shruti.o.gupta, In For each use this item in opList.Split(CChar(Environment.Newline)) and change the type argument to string.
Inside body of for each remove everything and use write line and include item

Regards,
Dominic :slight_smile:


#4

Hi @shruti.o.gupta,

Please find updated workflow, I hope this is what you wanted.

Reg,
Sarthak

2nd-copy.xaml (6.8 KB)


#5

Thanks it worked !!


#6

Thanks


#7

buddy after splitting how you stored each line of notepad to new string