2016-09-08 54 views
0

我在ssis中有一個腳本刪除了文件,我需要通過添加變量來修改腳本,以便可以動態執行過程。我將不勝感激,如果一些能幫助我通過展示如何在下面的腳本中添加變量: -基於變量SSIS腳本刪除文件

enter public void Main() 
    { 
     int RetentionPeriod = 0; 
     string directoryPath = @"\\ABCD\EFG\HIJ";--need to add location variable 
     string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.csv"); 
     foreach (string currFile in oldFiles) 
     { 
      FileInfo currFileInfo = new FileInfo(currFile); 
      if (currFileInfo.LastWriteTime < (DateTime.Now.AddDays(-RetentionPeriod)))---need to add date variable here 
      { 
       currFileInfo.Delete(); 
      } 
     } 
     // TODO: Add your code here 
     Dts.TaskResult = (int)ScriptResults.Success; 
    } 
} 

}

按照腳本我需要添加兩個變量,即位置變量和日期變量顯示。無論是變量具有字符串數據類型

我知道這個問題很愚蠢,但我沒有EXP書面SSIS腳本

回答

2
string directoryPath = Dts.Variables["User::NameOfStringVariable"].Value 

您還必須將變量添加到腳本任務配置上的ReadOnly列表。這裏是另外一個問題一個截屏,顯示你在哪裏使變量訪問腳本:

enter image description here

,並在情況下,你不知道在哪裏/如何將一個變量添加到包。一個簡單的方法是右鍵單擊控制流的灰色區域,然後選擇變量,然後調出變量窗口,然後簡單地添加所需的適當數據類型的變量。

enter image description here