3

File_NAME is readonly variable MyColumn is output column I have File_Name as ReadOnlyVariable in Script Component and I want to store this as output to use later in the package. Created Output column (myColumn) in Inputs and Outputs. Now trying to populate myColumn as File_Name

public override void CreateNewOutputRows()
{
    MyOutputBuffer.AddRow();
    MyOutputBuffer.MyColumn = ??User::FILE_NAME
}

How to put File_Name variable in MyColumn?

2
  • Your question is unclear. What is FILE_NAME? What is MyColumn? What do you mean by "store this as output"? Commented Jun 19, 2016 at 20:21
  • Question is edited now. Commented Jun 19, 2016 at 21:04

1 Answer 1

3

A script component allows you access SSIS variables in the Variables collection, once you've added them to the read or read/write collection.

The syntax for doing so is

MyOutputBuffer.MyColumn = Variables.FILE_NAME;

A script task is different in that you would need to access the Value method and then cast to the resulting value from Object to the correct type.

There are two other ways of adding the value of FILE_NAME into your Data flow. The second and more SSIS-centric way would be to use a Derived Column Component with an expression like

@[User::FILE_NAME]

assuming that you've defined this as a new column named MyColumn and have a type like DT_WSTR(120)

The other, assuming this was a Flat File Source, is to go to the Advanced properties and include the filename as a column.

I blogged about the latter approaches under What is the name of current file if you're looking for a thrilling read.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.