August 7, 2015 at 3:21 am
Hi ,
In my SSIS Package I am using Script task to check whether file exists or not.
I am having 3 variable as below
User::V_Filepath >File path
User::V_GeographyLevelFileName >Filename
User::V_FileExistsFlg >Flag
Below is the code I am using for same
String filepath = Dts.Variables["User:V_Filepath"].Value.ToString() + Dts.Variables["User::V_GeographyLevelFileName"].Value.ToString();
if (
File.Exists(filepath)
)
{
Dts.Variables["User::V_FileExistsFlg"].Value = 1;
}
MessageBox.Show(filepath);
MessageBox.Show(Dts.Variables["User::V_FileExistsFlg"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
But I am getting exception error.
find the attached screenshot of error
Regards,
Vipin jha
August 7, 2015 at 7:02 am
string FolderPath = Dts.Variables["User::V_Filepath"].Value.ToString();
string FileName = Dts.Variables["User::V_GeographyLevelFileName"].Value.ToString();
string fullPath = string.Format(@"{0}\{1}", FolderPath, FileName);
Dts.Variables["User::V_FileExistsFlg"].Value = File.Exists(fullPath);
int val = Convert.ToInt32(Dts.Variables["User::V_FileExistsFlg"].Value);
if (val==1)
{
MessageBox.Show("The file is exists");
}
else
{
MessageBox.Show("The file is not exists");
}
Kindly use above code.It is working fine for me.In your code check first line,you have missed ":" (semicolan) to add.
Thanks,
Saravanan S
August 7, 2015 at 7:41 am
if Dts.Variables["User::V_FileExistsFlg"].Value is a boolean, you should assign true or false, and not 1, right?
Also,if you append strings like that together, you have to be absolutely sure of ending slashes, right?
String filepath = Dts.Variables["User:V_Filepath"].Value.ToString()
+ Dts.Variables["User::V_GeographyLevelFileName"].Value.ToString();
"C:\Data" + "MyFile.xls" = "C:\DataMyFile.xls"
I think you want to use System.IO.Path.Combine to put the filename and path name together, and then use File.Exists.
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply