DotnetFactory Object in UFT

DotNetFactory object is another important utility object that can be used to use .Net API library. VBScript can be used to perform most of the operations. But .Net API is convenient and more powerful. Some of the useful code snippets of DotNetFactory object are given below. In below example, we have used below classes from .Net library.
  • System.IO.File
  • System.Environment
  • System.DateTime
  • System.Collections.ArrayList
 
Set file=Dotnetfactory.CreateInstance("System.IO.File")
file.writealltext "myfile.txt","This will be put in file"

Set env = Dotnetfactory.CreateInstance("System.Environment")

msgbox env.MachineName
msgbox env.OSVersion

Set dateTimeObject = Dotnetfactory.CreateInstance("System.DateTime")
Set myDate = dateTimeObject.Parse("09 Jan 1986")
 
msgbox myDate.Day & "/" & myDate.Month & "/" & myDate.Year
 
Set arrayList = DotnetFactory.CreateInstance("System.Collections.ArrayList")
arrayList.Add("Brisbane")
arrayList.Add("Mumbai ")
arrayList.Sort

msgbox arrayList.Count
msgbox arrayList.Item(1)                    

Complex problems, Simple Solutions