Solved

VB.NET SendKeys ... File Open window

Posted on 2011-03-23
6
948 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
  • 3
6 Comments
 
LVL 19

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 19

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 19

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now