從.Dtsx 檔案自動擷取版本編號
簡介:
簡介:簡介:
版本註解
版本GUI D次要版本
將 dtsx 檔案解析為 XML/文字:
使用正規表示式:
使用XML 解析器:
參考以下內容連結查詢:
Public Sub ReadPackagesInfo(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Read the file contents Dim strContent As String = "" Using sr As New IO.StreamReader(strFile) strContent = sr.ReadToEnd sr.Close() End Using ' Use Regex to extract package version and other properties strPackageFormatVersion = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value ' ... (Additional regex patterns for other properties) ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
從中提取資料未儲存在Sql Server 中的.dtsx 檔案:
Public Sub ReadPackagesInfoUsingXmlParser(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Load the file as XML document Dim xml = XDocument.Load(strFile) ' Create a namespace manager Dim ns As XNamespace = "www.microsoft.com/SqlServer/Dts" Dim man As XmlNamespaceManager = New XmlNamespaceManager(New NameTable()) man.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts") If Not xml.Root Is Nothing AndAlso Not xml.Root.Descendants(ns + "Property").Attributes(ns + "Name") Is Nothing AndAlso xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").Count > 0 Then ' Extract package version and other properties using XPaths strPackageFormatVersion = xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").FirstOrDefault.Parent.Value ' ... (Additional property extraction using XPaths) End If ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
以上是如何自動從多個 .dtsx 檔案中檢索版本號?的詳細內容。更多資訊請關注PHP中文網其他相關文章!