?
Solved

SSIS: Use Variable in C# Script task

Posted on 2014-11-26
2
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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