I am trying to loop through a folder. The suffix of each file can be found in a column in an SQL table. This suffix is the WHERE for my LINQ statement and is a variable in the script task (shown on comments). Where the predicate is true, I want it to return the value from another column on the same row in the SQL table, and assign the other column's value to another variable in my script task. For now I am just doing a MessageBox.Show to test.
I have set up an OLEDB connection manager in my SSIS package, I'm not sure how I can run the LINQ query inside the task, I think I'm missing something in how I have set up the connection. Any pointers would be gratefully received. Here's how far I've got:
public void Main()
{
string sourcePath = Dts.Variables["User::sourcePath"].Value.ToString();
string archivePath = Dts.Variables["User::archivePath"].Value.ToString();
string destinationPath = Dts.Variables["User::archivePath"].Value.ToString();
SqlConnection conn = new SqlConnection();
conn = (SqlConnection)(Dts.Connections["Server.Database"].AcquireConnection(Dts.Transaction) as SqlConnection);
DirectoryInfo directoryInfo = new DirectoryInfo(sourcePath);
FileInfo[] files = directoryInfo.GetFiles();
foreach (FileInfo fileInfo in files)
{
string fileName = fileInfo.ToString();
fileName = fileName.Split('_')[0]; // File Suffix
string destinationPrefix = "";
// LINQ HERE USING fileName variable:
//destinationPrefix = FROM t in Table where t.Column == fileName select destinationPrefixColumn
MessageBox.Show(destinationPrefix);
}
}