user138957
user138957

Reputation: 259

Trying to read text file

I have to read all lines of a text file to perform some some changements on it . My problem is that I didn't find how to read the path file :

string Source = Dts.Variables["User::VarFilesToMove"].Value.ToString();
string folder = Dts.Variables["$Project::FichierBanque"].Value.ToString() ;
string folderFtp = Dts.Variables["$Project::FtpFolderInLocation"].Value.ToString();
string file = folder  + Source + ".txt";
string[] lines = File.ReadAllLines(@"file");
//or string[] lines = File.ReadAllLines("file");
//string[] lines = File.ReadAllLines(file);

Many thanks for any help .

Upvotes: 0

Views: 119

Answers (2)

Muhammad Umar
Muhammad Umar

Reputation: 3781

First to ensure that file exist. Try this

if (File.Exists(file))
{
    string[] lines = File.ReadAllLines(file);
}

Upvotes: 2

Jakub Konecki
Jakub Konecki

Reputation: 46008

file is a string variable, just pass it to the method as parameter:

string[] lines = File.ReadAllLines(file);

Upvotes: 3

Related Questions