Solved

VB.NET SendKeys ... File Open window

Posted on 2011-03-23
6
962 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

713 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