Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
546 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | SSIS Integration Services (28 exercises) |
Topic ==> | Accessing file attributes (2 exercises) |
Level ==> | Harder than average |
Subject ==> | SSIS training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The folder above contains 6 files:
The permanent base file is there to ensure that SSIS always has something to find during the validation phase of your package.
Create a package called Open most recent file, and within this create this variable:
Note that your file path will be different.
Create a data flow task to read in data from your permanent base file:
Use a data viewer to show what you've loaded from the Excel workbook.
Tell your Excel connection to gets its path from the FilePath variable that you've created:
Set the ExcelFilePath to be the value of your variable.
Create a script task to loop over all of the files in the permanent base file's folder, working out which one was last changed, and setting this file's path into the FilePath variable at the end of this script.
Even for an experienced programmer this isn't that easy. The script you could use is shown below - it's up to you whether you refer to it!
Make a small change to one of the files in the folder at random. When you run your package, it should load data from this workbook.
Here's a script that you could use:
// get the current file path
string filePath = Dts.Variables["FilePath"].Value.ToString();
// get this file
var thisFile = new FileInfo(filePath);
// initially there is no file to use
FileInfo fileToUse = null;
// get a reference to this folder
var thisFolder = thisFile.Directory;
// loop over all of the files in this folder
foreach (var f in thisFolder.GetFiles())
{
// ignore base file, since this is accessed & updated during
// the validation stage, even though it's never used!
if (!f.FullName.ToLower().Contains("permanent base file"))
{
if (fileToUse == null)
{
// if this is the first file, set it to be the one
// to use (subsequent files may replace it)
fileToUse = f;
} else
{
// if this file was modified since the currently
// considered one, change the latter
if (f.LastWriteTime > fileToUse.LastWriteTime)
{
fileToUse = f;
} } } }
// update the file to be used
Dts.Variables["FilePath"].Value = fileToUse.FullName;
} }
When you've finished, don't forget to close down your package.
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.