SSIS 脚本任务读取文件

 

变量fileName输入参数,读取文件内容放到变量content中。

 1  Public   Sub  Main()
 2           '
 3           '  Add your code here
 4           '
 5           Dim  filename  As   String
 6           Dim  content  As  StringBuilder
 7          content  =   New  StringBuilder
 8          filename  =  Dts.Variables( " fileName " ).Value.ToString()
 9 
10           Try
11               '  Create an instance of StreamReader to read from a file.
12               Using  sr  As  StreamReader  =   New  StreamReader(filename)
13                   Dim  line  As   String
14               
15                   Do
16                      line  =  sr.ReadLine()
17                      content.AppendLine(line)
18                   Loop   Until  line  Is   Nothing
19                  sr.Close()
20 
21               End   Using
22 
23              Dts.Variables( " content " ).Value  =  content.ToString()
24 
25           Catch  E  As  Exception
26            
27              Console.WriteLine(E.Message)
28           End   Try
29 
30 
31 
32          Dts.TaskResult  =  Dts.Results.Success
33       End Sub
34 
35 

你可能感兴趣的:(读取文件)