[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

need help with vb Script for checking if file exists using script task in ssis

Posted on 2011-10-13
6
Medium Priority
?
862 Views
Last Modified: 2013-12-16
Hi i am writing a script task in ssis. I need assistance in writing the script task. i googled it as i am newbie to scripting, i need help. So here is the code i got. but the thing is I dont want to hard code the file name because there are four files that exists with different numbers on it with the timestamp on it for that particular day. Can I do that at the point of file location in this script without hardcoding the file. i check this code but its poping up a window. I don't want to see any pop window instead send an email to concerned using send mail task in ssis. Suggest me how can I go about it and how do i know if files doesnt exist. if doesn't exist send an email that says doesnt exist .. Please help me in writing


using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO; 

namespace ST_d4b3389a51734caa85bb7d3b9a843c90.csproj
{
  [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
  public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  {

    #region VSTA generated code
    enum ScriptResults
    {
      Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
      Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

    

    public void Main()
    {

      //USe your folder and file name here to check if exists

      if (File.Exists(@"D:\\YOURFILEFOLDER\\Test.txt"))       -- [b]I need to check if four files are added dynamically or using wild card like * to imply that four files exists...[/b]
      {
        Dts.Variables["FileExtFlag"].Value = 1;
        MessageBox.Show(Dts.Variables["FileExtFlag"].Value.ToString()); //comment out this line, just for testing the value of variable
      }
      else
      {
        Dts.Variables["FileExtFlag"].Value = 0;
        MessageBox.Show(Dts.Variables["FileExtFlag"].Value.ToString()); //comment out , just to check value
      }
      // TODO: Add your code here
      Dts.TaskResult = (int)ScriptResults.Success;
    }
  }
}

Open in new window

0
Comment
Question by:srionline2k6
  • 3
4 Comments
 
LVL 35

Expert Comment

by:sarabande
ID: 36978969
from the ".csproj" in namespace it seems it is c# code.

Sara

0
 

Author Comment

by:srionline2k6
ID: 37067187
Where I need to look my question. I haven't got any replies yet Let mw know where can i get replies
0
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 37075285
you could try

if (File.Exists(@"D:\YOURFILEFOLDER\Test1.txt") ||
    File.Exists(@"D:\YOURFILEFOLDER\Test2.txt) ||  
    File.Exists(@"D:\YOURFILEFOLDER\Test3.txt) ||  
    File.Exists("D:\\YOURFILEFOLDER\\Test4.txt) ) 
{

Open in new window


note when using the @ you can use single backspace \ in path. when you omit the @ you need the \\ casue backspace is escape character.

if you need more help you should use the request attention button (below initial question) to reschedule your question and get more answers as i am not much experienced in c#.

Sara
0
 
LVL 35

Assisted Solution

by:sarabande
sarabande earned 2000 total points
ID: 37075462
for more info on File.Exists see http://msdn.microsoft.com/en-us/library/x23stk5t(v=vs.85).aspx

wildcards are not supported with that statement.

search with wildcards could be done like

string[] files = Directory.GetFiles(@"d:\yourfilefolder", "test*.txt"); 
if (files.Length > 0) 
{    
      //file exist 

Open in new window



Sara
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question