1

Good morning all,

I am currently working on project for myself to make my life a bit easier and get job done a bit faster, but unfortunately I have faced an issue. My understanding of c# is not as advanced yet and I hope someone will be able to give me some sort of clue or solution.

To the point. Is there a way to copy data displayed in one program and paste it into another?

let's say:

program_1 - command line app where all my code is being implemented to

program 2 - windows form app ( this is an existing .exe file added as reference to program_1)

When starting program_1 this trigger specific option in program_2 and program_2 display result on screen. What I want to do is to automatically copy content displayed in program_2 and:

a) save outcome as .txt using program_1

or

b) sent outcome directly to e-mail address, also using program_1

I was trying to use TextBox. options, GetData(), but I must be missing something. I would be much grateful for any sort of help.

Code:

Process app = Process.Start("SalesReport.exe");
Thread.Sleep(10000); 
TextBox textBox1 = new TextBox();
textBox1.SelectAll();
textBox1.Copy(); 
app.Kill(); 

this is just basic function to launch report, this displays the result as table in program_2.

Vladimir
  • 1,380
  • 2
  • 19
  • 23
Arcadio R
  • 21
  • 3
  • "program_2 display result on screen" How is it displayed: a graph, a webpage, an image, a video, a grid, a hologram ... ? – Peter B Nov 21 '16 at 11:14
  • First - Welcome to Stack Overflow ! Simplest option available is indeed txt file, you also can use no sql database or even tcp sockets. Can you specify where you get an error and provide your code here ? – Vladimir Nov 21 '16 at 11:15
  • @PeterB The data in displayed as table containing few rows and cells. Unfortunately I cannot attach scrrenshot, but it look very simillar to view such as access or any other db. – Arcadio R Nov 21 '16 at 11:46
  • @Vladimir `Process app = Process.Start("SalesReport.exe");` `Thread.Sleep(10000);` `TextBox textBox1 = new TextBox();` `textBox1.SelectAll();` `textBox1.Copy();` `app.Kill();` this is just basic funtion to launch report, this displays the result as table in program_2 (SalesReport.exe). – Arcadio R Nov 21 '16 at 11:52
  • so from console app you launch Winform application (SalesReport.exe), SalesReport has a textbox witch get information form the txt file ? In your code you only show that Windform app create textbox, you have not provided a code that populate textbox. And it`s better to provide a code in a formatted way in the question – Vladimir Nov 21 '16 at 13:01
  • @Vladimir I know it's better, but as newbee I am still learning, I was trying to format the code and post it as it should, but could not find a way how to do it... the only way i have found was `using this format`. I know it's not the best. Take my apologies. And this is the actual problem I do have. I am not sure that text was copied or not into text box. Report.exe is the application itself and I don't have an access to view it's source code, and I don't know that TextBox has selected and copied data I wanted. How can i check it or populate mentioned textbox? – Arcadio R Nov 21 '16 at 13:34
  • Please [check](https://www.altova.com/images/screenshots/database-contents-diff.png), this is kind of outcome I do receive from SalesReport.exe once completed. Of course I am not receiving image, but seperate screen of db. – Arcadio R Nov 21 '16 at 13:37
  • Alright, so we have some Visualization program without source code *SalesReport* (this application only show the data and do not create txt file with required contents), and we need to get the data from it ? Is that right ? – Vladimir Nov 21 '16 at 15:18
  • @Vladimir, that's correct. This SalesReport.exe is something like automated report wizard. Once launched it's pulling data of database, creating a tables and showing results. Then all that data need to be rewritten into seperate sheet for further analysis. And imagine pulling and rewriting that data around 30 times a day to perform seperate analysis. Being able to write c# script to copy that data and save it in external file or even send to to e-mail would be much helpful. i was even trying to perform screen capture and then use some sort of bmp to txt converter... but not luck. – Arcadio R Nov 21 '16 at 16:48
  • you need some kind of Winforms UI Scrapping tool. Might take a look at https://blogs.msdn.microsoft.com/oldnewthing/20160314-00/?p=93152 Note that solution you trying to made if more complicated than you expected. Might need to use [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] and others Win32 methods... – Vladimir Nov 21 '16 at 17:05
  • @Vladimir I see what you talking about. But how can I implement this into 3rd party exe file? – Arcadio R Nov 22 '16 at 14:17
  • Maybe there is a easier way such as screen capture (active window - I mean SalesReport.exe window only) and then use OCR to convert data into editable format? – Arcadio R Nov 22 '16 at 14:20
  • @Vladimir I am trying to play with UI Automation from link you have provided... but there is an argument missing from `enumerable.empty` `return parent == null ? Enumerable.Empty() : parent.FindAll(TreeScope.Children,` Is it because some `` is missing, if so, what should be put in place in this case. – Arcadio R Nov 22 '16 at 15:15
  • http://stackoverflow.com/questions/10705363/how-to-access-a-window might help you – Vladimir Nov 22 '16 at 15:40
  • @Vladimir right ok, we going somewhere. What if I would like to reference to different stand-alone app or different menu item within notepad? lets say `Edit -> Go To...` – Arcadio R Nov 22 '16 at 16:36
  • And by screen capture of specific window I meant. for example I will have opened few apps ... app1, app2 and app3... what is I would like to do a snapshot only of screen of app3? – Arcadio R Nov 22 '16 at 16:40
  • even if you would choose screenshot option - still user32.dll is needed, take a look at http://stackoverflow.com/questions/891345/get-a-screenshot-of-a-specific-application – Vladimir Nov 22 '16 at 16:49
  • @Vladimir I have seen it already, even has tested it, but unfortunately I am missing something... some references or class, I know this may sound daft, but should this code be implemented into Main() or before as seperate classes and then called from main. I know that I am missing something, but not really sure what is it. – Arcadio R Nov 22 '16 at 16:57

0 Answers0