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

Advertisements

March 15, 2008 - Posted by | DotNetFactory, Uncategorized | , ,

11 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

  7. Hi Mohan,
    I have created a form using dot net factory..form is having a text box and a button (“ok”)..if some one clicks on ok button then message should be displayed..how to achieve the same…

    i am not getting the syntax to click on the button…plz help
    Warm Regards,
    Bibek Khatiwwaraa

    Comment by Khateee | October 21, 2009 | Reply

  8. I face the same issue – My script hangs on the line “fd.ShowDialog()” and then i have to forcefully close it from task manager

    Comment by Dev | July 13, 2010 | Reply

  9. hi Mohan
    how to call java class object(which is registered as COM object) in VB

    i tried its throwing err as cannot create object

    Comment by vidhyalingam | August 2, 2010 | Reply

  10. hi Mohan,

    i am sudheer and i had a small requirement. Thats open a folder and refresh it and then pick first file from that folder.
    can u help me find solution

    Comment by sudheer | October 26, 2010 | Reply

  11. hi Mohan,

    i am sudheer and i had a small requirement. Thats open a folder and refresh it and then pick first file from that folder.
    can u help me find solution.

    Comment by sudheer | October 26, 2010 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: