Solved

SSIS: Use Variable in C# Script task

Posted on 2014-11-26
2
198 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
ID: 40468041
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
ID: 40468704
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

914 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

12 Experts available now in Live!

Get 1:1 Help Now