Search code examples
c#sql-serverssisetlscript-task

SSIS Script Task check folder for any XML files


I'm using SQL Server 2014 \ SSIS.

I have the below code within a Script Task to check if a folder contains any XML files:

using System;
using System.IO;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

    public void Main()
    {
        // TODO: Add your code here

        string folder = Dts.Variables["$Project::XMLFilePath"].Value.ToString();     

        Dts.Variables["User::fileExists"].Value = Directory.EnumerateFiles(folder, "*.xml").Any();


        Dts.TaskResult = (int)ScriptResults.Success;
    }

However, I keep receiving the error:

'System.Collections.Generic.IEnumerable' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found

Why does it not like the .Any? I'm using the System.IO namespace.


Solution

  • Add the LINQ namespace:

    using System.Linq;