Solved

VB.NET SendKeys ... File Open window

Posted on 2011-03-23
6
971 Views
Last Modified: 2012-05-11
I have a VB.NET application that I am writing.  I need to capture a file by the user and feed that filename into the "file open" of another application.  I am simulating it in this example with notepad.  

The code works until it comes to populating the "open" window in notepad.  

I have tried SendKeys.Send and SendKeys.SendWait

NOTE:  The application (i.e. NOTEPAD) will already be open.

- - - - sample code excerpt - - - -
            openFD.ShowDialog()
            AppActivate("untitled - notepad")
            SendKeys.SendWait("%FO")
           
            ' All is well until this next line.  This line does not work
            SendKeys.SendWait("{quote}" & openFD.FileName & "{quote}{enter}")
0
Comment
Question by:javajws
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 20

Accepted Solution

by:
darbid73 earned 500 total points
ID: 35197219
Whenever I see send keys I always think - is this really the only way to do it.  It is arguable that sendkeys is not realiable.

If I understand you correctly the user is going to use the windows dialog to open a file.  You would like to intercept or listen to this process and get the file that is being opened and use that information somewhere else?
0
 
LVL 9

Author Comment

by:javajws
ID: 35197354
My program will ask the user for the filename with the Windows dialog to open a file.  That filename (and path) will not be opened, it will be used to copy the file from the network folder to a local folder and open the local file in another program (for now, Notepad).  

I have the first part working.  It asks for a file, copies the file from the network path to the local path.  I am then able to locate the application (in this case Notepad) using "AppActive".  

Now I want to simulate "File...Open" and feed the path/filename, to open the user requested file.
0
 
LVL 20

Expert Comment

by:darbid73
ID: 35197401
Ok so you have the full path name to the file which is now saved locally.

Your example (which I know is an example) is with notpad.

I would use something like this
System.Diagnostics.Process.Start("notepad.exe", "mydocument.txt")

Open in new window


Why do you need to imitate how a user opens it?

What is the program you really want to open the file in?
0
 
LVL 20

Expert Comment

by:darbid73
ID: 35496317
The questioner wants to open a file with, in this example notepad.

His example has been answered and one could assume satisfactorily, as he has not questioned it or asked for more assistance for more than a month.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question