Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:17:45+00:00 2026-05-23T16:17:45+00:00

I am creating an SSIS package and the first step is to get a

  • 0

I am creating an SSIS package and the first step is to get a list of files stored in a file and store this information in an object variable. I pass this variable to a task that tries to open the list of files. However, the open file task fails if there are no files to open because the folder is empty.

I am relatively new to using SSIS and was curious on how to rewrite an expression that checks to see if the object variable is empty and if it is empty not allow the open file task to run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:17:46+00:00Added an answer on May 23, 2026 at 4:17 pm

    You don’t need to use an object variable to loop through files in a folder. You can easily achieve that using Foreach Loop Container. Following example demonstrate how this can be done. The example was created in SSIS 2008 R2.

    Step-by-step process:

    1. Let’s assume that we need to loop through the files in the path C:\temp as shown in screenshot #1.

    2. On the SSIS package, create three variables namely FolderPath, FilePattern and FilePath. Refer screenshot #2. Set the FolderPath variable to the folder that you would like to loop through, here in this case I have chosen C:\temp. Set the FilePattern variable to a pattern that your files should match, here I would like to loop through all files so I have used *.*. If you would like to loop through only Excel 2010 files, then you can use *.xlsx. It can accept only one pattern. Don’t set any value to variable FilePath because this will be assigned with a value when the Foreach Loop Container loops through each file in the folder.

    3. On the package’s Control Flow Tab, place a Foreach Loop container and then place a Script task within the Foreach loop container. In this example, we are going to simply loop through each file and display their names and not do anything more. Refer screenshot #3.

    4. Configure the Foreach Loop Container as shown in screenshots #4 and #5. On the Collection section, we have configured the Expressions to use the variables FolderPath and FilePattern. On the Variable Mappings section, we have told the container to store the file path value into the FilePath variable.

    5. Inside the Script task, replace the Main() method code with the code given under Script Task Code section. There is nothing fancy in the code. It simply displays the file path in a message box.

    6. Screenshots #6 – #11 shows a sample package execution and how each file in the folder is looped through. Please note the screenshot #11, the script task is marked with green color stating that the package successfully executed the task.

    7. Now, let’s delete all the files in the folder C:\temp as shown in screenshot #12.

    8. If we execute the package now, the tasks within the Foreach loop container will not executed because there are no files to loop through and the folder is empty. Refer screenshot #13. Please note that the script task is marked with white color stating that the package didn’t execute the script task and it skipped the section.

    9. This is only a simple example. You can do whole lot more than simply display names of the files. You can have other tasks within the Foreach Loop container and pass the FilePath variable to process the files.

    Hope that helps.

    Script task code:

    C# code that can be used only in SSIS 2008 and above.

    public void Main()
    {
        Variables varCollection = null;
    
        Dts.VariableDispenser.LockForWrite("User::FilePath");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        MessageBox.Show(varCollection["User::FilePath"].Value.ToString(), "File Path");
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    

    Screenshot #1:

    1

    Screenshot #2:

    2

    Screenshot #3:

    3

    Screenshot #4:

    4

    Screenshot #5:

    5

    Screenshot #6:

    6

    Screenshot #7:

    7

    Screenshot #8:

    8

    Screenshot #9:

    9

    Screenshot #10:

    10

    Screenshot #11:

    11

    Screenshot #12:

    12

    Screenshot #13:

    13

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an SSIS 2008 package that reads data from an ASCII flat file
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Is it possible to create an SSIS package that can be passed a file
I am creating an ASCII output file contain some information and two of my
Am trying to execute ssis package using dtexec utility from c# app(Creating New Process,
Please read Update1 first! This is SSIS specific question. I have the following tasks:
Dears, in SSIS 2008 when I try to create new package I get following
My app generates SSIS packages for importing data from Excel files. This is done
Creating servlet that implements contextInitializer interface in this code, then accessing file inside contextinitialized()
I have ssis package in that I'm taking values from flat file and insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.