HomeInterview QAQuick TipsCheck if file exists: using SSIS

Comments

Check if file exists: using SSIS — 9 Comments

  1. Very great post. I just stumbled upon your blog and wished to say that I have truly loved surfing around your weblog posts. In any case I will be subscribing for your rss feed and I am hoping you write again soon!

  2. I’m sure this really the most important knowledge personally. At this point relieved looking at your personal write-up. Nevertheless would you like to comments about many typical facts, The web site personal taste is ideal, the particular reports is within simple fact excellent. Beneficial approach, Kind regards!

  3. I need to verify if a file exists and following the above procedure and having issues running the package

    Variable FileExists is boolean set to False created at Package level
    and have code similar to one above in Main() and constraint is set to “@[User::FileExists]==True”

    ****Script code
    System.IO.FileInfo myFile = new FileInfo(Dts.Variables[“User::SAPFileLocation”].Value.ToString());
    Dts.Variables[“User::FileExists”].Value = myFile.Exists;
    Dts.TaskResult = (int)ScriptResults.Success;
    **** ScriptCode

    I see the following error messages in package doesn’t execute.

    Error: The wrapper was unable to set the value of the variable specified in the ExecutionValueVariable property.

    Error: The type of the value being assigned to variable “User::FileExists” differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

    Any thoughts what i need to do ?

    • Hi Sai,
      Yes, The method seems to be correct. What i can see is that, you are directly assigning the value of “myFile.Exists” to the SSIS variable and thats what could be causing an issue. What version of SSIS (BIDS) are you using. I have created this demo in SQL 2012. i will check this today when i reach home.

      meanwhile, you can try this solution:

      ****Script code
      // Set Your File’s Path Here
      string sourceFilePath = Dts.Variables[“PATH_SRC_FILE”].Value.ToString();

      // Check if your file(s) is available
      string[] filesFound = Directory.GetFiles(sourceFilePath, fileFormat, SearchOption.TopDirectoryOnly);

      // If Found then set the value, True
      if (filesFound.Length > 0)
      {
      Dts.Variables[“User::FileExists”].Value = true;
      }

      Dts.TaskResult = (int)ScriptResults.Success;
      ****Script code

      Please let me know if you still face any issues on this.
      Thanks, Khilit

      • I am using BIDS 2008 and it still doesn’t work. I dont think its an issue with the script , since i removed everything within main() and it still shows the same error.

  4. if I need to check for the file with file mask.for example Test_MMDDYYYY.csv, then in this case how can I write the C# code using the same mentioned above

  5. I am having file declared as variable having mask Pay_MMDDYYYY.But my code is picking only that file which i gave in variable.It doesn’t pick file having any other datetimestamp other than this.how to pick the files having different mask.need to write it in C#

Leave a Reply

Your email address will not be published. Required fields are marked *

HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>