none
extract validation

    Question

  • Hi All,

    I have this script in script task in SSIS.

    string
    Dts.Variables["InputPath"].Value;
    {
    if (Directory.Exists(strpath))
    {
    // Process the list of files found in the directory. 
    string strfilenamewithext = "";
    string[] fileEntries = Directory.GetFiles(strpath, "*.EXTRACT*");
    foreach (string fileName in fileEntries)
    {
    strfilenamewithext = Path.GetFileName(fileName);
    if (strfilenamewithext.Equals("ExtractToBeLoad.EXTRACT01"))
    {
    Dts.Variables["Extract01"].Value = strfilenamewithext;
    Dts.TaskResult = (int)ScriptResults.Success;
    }
    else
    {
    Dts.Events.FireError(52, 
    "File Validation", "Invalid File Name - " + strfilenamewithext, "", 0);
    Dts.TaskResult = (int)ScriptResults.Success;
    }
    }
    }

    Script work fine until i place another .extract01 file but different file name to the path configured in connection string. I want the SSIS Package to ignore that file and continue loading file that has a correct file name.

    Thanks

    Tuesday, July 30, 2013 3:17 AM

Answers

  • I need one single line 

    i want to validate the file if it is filename format "ExtractToBeLoad.EXTRACT01". and if it, the package should wok fine

    string FolderPath="Your folder to Look";

    If File.Exists(FolderPath + "/" + ExtractToBeLoad.EXTRACT01)>)

    {

    /*do you task extract thing*/

    /*package should wok */

    }

    2nd - if there is another .EXTRACT01 file but different filename, package should ignore it and continue loading but it should fire warning.

    <put a new IF condition here looping through folder and check another .EXTRACT01 file but different filename and raise warning >

    3rd - if there is no file or wrong file (ex: .EXTRACT1) in path, success but it wont be load to my staging table and stop the process in script task. and will fire an error.

    <Nothing to do because it loads only in case of file  ExtractToBeLoad.EXTRACT01>


    Thanks and Regards, Prajesh Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Wednesday, July 31, 2013 10:32 AM

All replies

  • If you want to ignore the 'error' then you should remove the FireError line in the else.

    But what are you trying to accomplish with this Script Task? An if file exists functionality?


    Please mark the post as answered if it answers your question | My SSIS Blog: http://microsoft-ssis.blogspot.com | Twitter

    Tuesday, July 30, 2013 5:43 AM
    Moderator
  • 1st - i want to validate the file if it is filename format "ExtractToBeLoad.EXTRACT01". and if it, the package should wok fine

    2nd - if there is another .EXTRACT01 file but different filename, package should ignore it and continue loading but it should fire warning.

    3rd - if there is no file or wrong file (ex: .EXTRACT1) in path, success but it wont be load to my staging table and stop the process in script task. and will fire an error.

    Wednesday, July 31, 2013 3:53 AM
  • Personally, I would not do this with a script task I would have a ForEach enumerator looping through files.


    Kind regards M


    • Edited by M Vega Wednesday, July 31, 2013 8:16 AM
    Wednesday, July 31, 2013 8:16 AM
  • I need one single line 

    i want to validate the file if it is filename format "ExtractToBeLoad.EXTRACT01". and if it, the package should wok fine

    string FolderPath="Your folder to Look";

    If File.Exists(FolderPath + "/" + ExtractToBeLoad.EXTRACT01)>)

    {

    /*do you task extract thing*/

    /*package should wok */

    }

    2nd - if there is another .EXTRACT01 file but different filename, package should ignore it and continue loading but it should fire warning.

    <put a new IF condition here looping through folder and check another .EXTRACT01 file but different filename and raise warning >

    3rd - if there is no file or wrong file (ex: .EXTRACT1) in path, success but it wont be load to my staging table and stop the process in script task. and will fire an error.

    <Nothing to do because it loads only in case of file  ExtractToBeLoad.EXTRACT01>


    Thanks and Regards, Prajesh Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Wednesday, July 31, 2013 10:32 AM