October 25, 2006 at 9:45 am
How would I convert the following code to vb.net? Thanks...
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim objFSO, objFolder, colFiles, strFilesExists
DTSGlobalVariables("ImportDirectoryPath").Value = DTSGlobalVariables("FileLocation").Value
SET objFSO = CreateObject("Scripting.FileSystemObject")
SET objFolder = objFSO.GetFolder(DTSGlobalVariables("FileLocation").Value)
SET colFiles = objFolder.Files
strFilesExists = "NO"
If colFiles.Count > 0 Then
For Each objFile In colFiles
'Look to see if files exists
IF UCASE(Left(objFile.Name, 3)) = "RCC" THEN
'If atleast one exists move on
DTSGlobalVariables("FileName").Value = objFile.Name
DTSGlobalVariables("FileCreateDate").Value = Mid( DTSGlobalVariables("FileName").Value , 4 , 10 )
DTSGlobalVariables("ConnectionString").Value =DTSGlobalVariables("FileLocation").Value + "\" + objFile.Name
strFilesExists = "YES"
Exit For
END IF
Next
End IF
If strFilesExists = "NO" Then
Main = DTSTaskExecResult_Failure
Else
Main = DTSTaskExecResult_Success
End if
End Function
October 26, 2006 at 7:09 am
A literal transalation might look like this in a script task, but you might do better with a ForEach File container.
Imports
System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim sPath As String = Dts.Variables("FileLocation").Value.ToString
Dim objFiles As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = _
My.Computer.FileSystem.GetFiles(sPath, FileIO.SearchOption.SearchTopLevelOnly, "RCC*.*")
If objFiles.Count > 0 Then
Dim sName As String = System.IO.Path.GetFileName(objFiles(0))
Dts.Variables("FileName").Value = sName
Dts.Variables("FileCreateDate").Value = sName.Substring(3, 10)
Dts.Variables("ConnectionString").Value = objFiles(0)
Dts.TaskResult = Dts.Results.Success
Else
Dts.TaskResult = Dts.Results.Failure
End If
End Sub
End Class
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy