Solved

SSIS: Use Variable in C# Script task

Posted on 2014-11-26
2
206 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

14 Experts available now in Live!

Get 1:1 Help Now