Quick test professional

QTP Tips QTP codes QTP Faqs and more

OpenFileDialog In QTP with help of DotNetFactory

 Set fd = DotNetFactory.CreateInstance(“System.Windows.Forms.OpenFileDialog”, “System.Windows.Forms”)
fd.InitialDirectory=”c:\\”
fd.Filter=”txt files (*.txt)|*.txt |All files (*.*) |*.*”
fd.RestoreDirectory=true
fd.FilterIndex=2
fd.ShowDialog()
msgbox fd.FileName

Author: Mohan Kakarla

March 15, 2008 - Posted by quicktestprofessional | DotNetFactory, Uncategorized | , , | 6 Comments

6 Comments »

  1. great thX!!!

    Comment by axel79 | April 4, 2008 | Reply

  2. I find it of great help
    However I am not able to generate a list box with few values in it which will help to select a input value out of it.

    Comment by Neelesh | December 3, 2008 | Reply

  3. However I am not able to generate a list box with few values in it which will help to select a input value out of it.

    Comment by Neelesh | December 3, 2008 | Reply

  4. Neelesh ,
    Use the following code to generate a list box with few values using dotnet factory.

    Set objForm = DotNetFactory.CreateInstance(“System.Windows.Forms.Form”, “System.Windows.Forms”)
    Set objBtn1 = DotNetFactory.CreateInstance(“System.Windows.Forms.Button”, “System.Windows.Forms”)
    Set objList1 = DotNetFactory.CreateInstance(“System.Windows.Forms.ListBox”, “System.Windows.Forms”)
    x=200
    y=100
    Set s1 = DotNetFactory.CreateInstance(“System.Drawing.Size”,”System.Drawing”,x,y)
    x1=80
    y1=40
    Set p1 = DotNetFactory.CreateInstance(“System.Drawing.Point”,”System.Drawing”,x1,y1)

    objList1.size=s1
    objList1.Location=p1

    objForm.Controls.Add(objList1)
    objList1.MultiColumn=False
    objList1.SelectionMode = objList1.SelectionMode.MultiExtended
    objList1.BeginUpdate()
    objList1.Items.Add(“India”)
    objList1.Items.Add(“USA”)
    objList1.Items.Add(“UK”)
    objList1.Items.Add(“Canada”)

    objList1.EndUpdate()
    objList1.SetSelected 1, True

    objBtn1.Text=”OK”

    p1.Y=Cint(p1.Y)+CInt(objList1.Height)+20
    objBtn1.Location=p1

    objForm.CancelButton=objBtn1

    objForm.Controls.Add(objBtn1)

    objForm.StartPosition=CenterScreen
    objForm.Text=”Mohan kakarla”
    objForm.ShowDialog
    msgbox objList1.SelectedItem

    Let me know if it serves ur requrement

    Comment by quicktestprofessional | December 4, 2008 | Reply

  5. Hi Mohan,

    I need some tips for designing QTP framework & creating master script. Kindly help me

    Nirmal

    Comment by Nirmal Kumar | December 9, 2008 | Reply

  6. Hi Mohit,

    i tried the code above in the page to get the file open dialog box at run time allowing user to select the file he wants to open. My script hangs on the line “fd.ShowDialog()” and then i have to forcefully close it from task manager. please revert me on shekhar.sharma@headstrong.com in this regards.

    thanks,
    Shekhar

    Comment by Shekhar Sharma | June 30, 2009 | Reply


Leave a comment