Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 read filename

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-10-07 : 07:33:37
In ssis 2008 script task, I would like tho get the name of the file as follows but the mesasge box shown an empty string. Do you see why please? thanks

public void Main()
{
Dts.Variables["FileName"].Value = System.IO.Path.GetFileName(Dts.Variables["FileName"].Value.ToString());
MessageBox.Show(Dts.Variables["FileName"].Value.ToString());

Dts.TaskResult = (int)ScriptResults.Success;
}

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 07:44:45
yyou're trying to assign filename stored in fileName variable to itself? sorry posted code doesnt make much sense

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-10-07 : 07:50:58
I see what you mean...
In that case what should this line be to get the filename?
I think I have to to pass the filelocatioin path but how and should it be hard coded?
Thanks
Dts.Variables["FileName"].Value = System.IO.Path.GetFileName(
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 07:52:39
you've to pass file location path. why not hold it in another variable and pass it as input to script?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-10-07 : 09:36:11
In scrip task editor, The readonlyVariables is set to User::SourceDirectoryPath and ReadWriteVariables set to User::FileName

Error is:
The element can not be fouond in a collection

public void Main()
{
Dts.Variables["FileName"].Value = System.IO.Path.GetFileName(Dts.Variables["SourceDirectoryPath"].Value.ToString());
MessageBox.Show(Dts.Variables["FileName"].Value.ToString());

Dts.TaskResult = (int)ScriptResults.Success;
}

Any thouoghts please?
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 12:23:31
did you add sourcefilepath variable in package at all?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-10-07 : 12:58:29
got it, thanks again.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 13:07:55
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -