Script task file check error

  • 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

  • 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

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply