Solved

SSIS: Use Variable in C# Script task

Posted on 2014-11-26
2
192 Views
Last Modified: 2016-02-11
Hi there,

How can I pass the following user defined variable to a C# script task. It's basically the folder path:

User defined variable is:
User::Source_Folder = \\14.100.26.12\dashboard

Open in new window


and the C# code I want to replace it with is the path as indicated below:
        public void Main()
        {
            string[] files = System.IO.Directory.GetFiles(@"\\14.100.26.12\dashboard", "AGINGANALYSIS*.txt", System.IO.SearchOption.TopDirectoryOnly);
            System.IO.FileInfo finf;

Open in new window


Thanks,

OS
0
Comment
Question by:onesegun
2 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
You are accessing the variables using the Dts.Variables collection.
Create a string variable in your C# code and access the variable using this code:
string sourcePath;
sourcePath = (string) Dts.Variables["Source_Folder"].Value;
string[] files = System.IO.Directory.GetFiles(sourcePath, "AGINGANALYSIS*.txt", System.IO.SearchOption.TopDirectoryOnly);

Open in new window

0
 

Author Closing Comment

by:onesegun
Comment Utility
Thanks Chaau. I knew I had to assign the SSIS variables to a declared variable inside the script but was frustrated by the syntax.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now