Copy and paste content of stand-alone in c# - c#

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.

Related

TextBox save value/input automatically

I would like to save a few values ​​from text boxes that should be loaded into the text boxes every time I restart my program.
However, since my customers all use different values ​​and should not re-enter them with every restart, I thought I could save these values ​​somehow.
But I have no idea how to do that.
my program is also tied to a database if there is a clean way, I would choose that too. my customers all have an account to log in to. but it can also be a simple .txt or XML file, but how does that work?
I working with visual Studio C# WinForms.
Windows Forms comes with Settings, which allow you to save variable values and load them back up the next time your program is run. The Designer allows you to create settings and set the data types for them. See the Microsoft documentation in the link above for more information.

CodedUI Test- Mouse.Click() on control dose not give expected outcome

I am using Visual studio 2010 to create CodedUI Scripts.The application under Test is a web based Loan origination application .
I am automating a part where user enter's zip code and clicks on search.
when I enter zip code manually and click on search the response is received instantly.
But when the same is done with code,Zip code is successfully sent and search button is clicked but application dose not respond.
Mouse.Click(ContactInformation.ContactInformationForm.PropertyAddress.ImageZipLookup);
Just wanted to understand if this is a playback issue and is there a alternative for using mouse.click()
Most likely, the definition for the submit button is incorrect in your recording. Open the .uitest file, find the control in question in the tree, and open the SearchProperties in the properties of the control. Verify that against the source on the page, and then try again. It's possible that the recording identified a parent HtmlDiv object or something that's receiving the input rather than the button itself (or link, if that's the case).
Personally, while I'm looking at the SearchProperties, I'd remove any properties that are unnecessary. If there's an ID or unique class for the object in question, I'd stick with that alone rather than identifying six or seven other traits that may not be correct on each run (.css styles, inner text, etc. can change depending on your app).
Just be sure you edit the SearchProperties in the UI rather than the text editor, as the .designer.cs file is recreated each time you run the Test Builder, so you would lose any changes you make directly to that file.

C# Change File Location For Next Time Program Runs

I am relatively new to C#, however I do have some basic knowledge of code from courses in high school and university. However, there is one thing I have not been able to figure out over the years. I am currently making a Form Application for a database system that stores information in a List using Visual Studios 2010.
On my main form; when the save button is pressed, the information is then serialized into an XML file. When the information is loaded, the information is then deserialized and put into the List for use in the code. All this is working correctly.
This process of saving and loading is done based on a string which contains the file path. This string is the location of a folder on my desktop (I put it there for easy access), and I am able to change the string in the code to basically move where the information is stored.
However, I have a separate "Admin" form which is able to change this file path string. When the user clicks the button to change the file path, I get the input from a text box, check its formatting, move the current file to the new location and update the location for the save method so changes can be saved before the program is closed. From there, the program reacts the same way as if I had changed the string from inside the code.
The problem occurs when I close the program. I do not know how to tell the program when it runs again that the location has been changed from the default and look for the file in the new location. The program reacts just like the file was missing (like it should) when it looks in the default location.
So basically, how do I tell the program that the save location was changed from when it was last run so it knows to load the info from a new location?
I have tried looking for an answer since high school (about 2 years ago) and have not found a solution. As a result I usually just keep the save location as the default (which I set it to) and don't try to change it. But this time, its important that the save location can be customized. My experience with Visual Studios is limited, as everything I know is from messing around with the program and looking up stuff when needed.
If needed, I can post snippets of my code. Thank you in advance!
It seems like what you really want is to save some user-defined settings for recall at run-time. Here is a MSDN link describing some basic conventions for storing / retrieving these settings.
https://msdn.microsoft.com/en-us/library/bb397750(v=vs.110).aspx
A *.config file would suffice (depending on the scale of the application).
Otherwise, you may want to go down the route of storing these settings in a database (if the scale is rather large, or if user-authentication is required for the application).
Here is another previous question dealing with this same subject (regarding App.config files):
What is App.config in C#.NET? How to use it?
I recommend using a config file where the .exe is, and write the location there, then read it in on program startup.
In particular .net provides this class which can manage your config file for you (assuming you have an app.config in your solution, otherwise create one)
https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings(v=vs.110).aspx

Add button and custom functionality to adobe reader

I am working on a WPF 4.5 application which needs to interact with PDFs and I am stuck with an issue as described below:
I have template pdfs stored at a specific location. Based on requirement, a copy of the template pdf is created. This pdf has certain fields including text boxes, dropdowns etc. Some of these fields need to be pre-populated like the dropdown values.
Once it is ready, I need to open it, and let the user complete the form. Once completed, the user saves the file and closes it.
Now I need to read the file and send the updated data to the DB. I was able to do all this using iTextSharp by launching the PDF in a separate process and handling the Exited event. Now, the problem I face is this solution does not work if the user uses the SaveAs option to change the name or location of the opened file.
I thought if it would be possible to disable the Save options and add a button on the form clicking which would automatically save the form and close it at the expected location would be a possible solution.
My questions are:
1) Is it possible to find out using the argument of the Exited event handler to find out the saved file name and location? As soon as the user saves the file with a different name, the title of the reader gets updated with the current file name. So I am assuming that the current process is using the latest file.
2) Is it possible to disable the SaveAs and Save file options and close the file on click of a button in the form, using Adobe SDK (JavaScript or plugin or API)?
3) If I use the Adobe SDK, do all the systems on which the application would be installed need to have a licensed version of the Adobe Acrobat?
If the above options are not possible then we would have to settle with dynamic forms. We wanted to experiment with PDF since it is easy to create, and supports image annotations, for which we might need to develop a separate solution, if the above options are not feasible.
I know this is not a very specific programming question, but I need help in order to be able to figure out which path I can go on to be able to achieve the goal.
Please mark duplicate with the link to the other SO question if it a duplicate since I have not been able to figure out one.
Would appreciate answers, links to other posts on SO that are specific to the questions asked.
Please avoid opinion based answers.
Any help would be appreciated.
Any constructive criticism is also welcome.
There is a heavy-handed way to prevent an Acrobat user from Saving a file. In Acrobat, create a Javascript that executes when "Document Will Save." A script like this causes the application to hang rather than Save the file:
var key = "" + this.getField("Password").value;
if (key != "QWERTY") {
app.alert ("No changes to this PDF are allowed,
so you may not Save it.
You will now have to Force Quit or End Task.");
while (true) {};
}
I am not proud of this, but it does the job. You might want to erase the password field before saving.

.NET 4.0 Automating/Scripting certain actions

I am a junior at university and quite new to the .NET framework.
Currently at my work in IT, there is a certain process in which an employee checks a MS office file, opens x applications, one after the other, and copies y files and waits on z conditions, one by one.
This process is quite long and tedious and very prone to human error. As such, I was wondering if .NET allows for some application to script this given sample procedure:
open a program,
input a string argument from an excel file,
get the output of the program,
paste the output of the program into another program,
get the output of the 2nd program,
open the output as a folder,
etc
The user should do as little work as possible (supplying some file paths and log-in credentials once and pressing some Start button).
If so, if someone could recommend a few good libraries/API to look at, it would be much appreciated.
Thank you for your time.
edit 1: System.Diagnostic.Process seems to not handle argument passing very well
Try using Powershell, it is much better suited to what you are trying to do. Good place to start:
http://technet.microsoft.com/en-us/library/ee221102
I think you could do that more easily with AutoIt.
.NET/c# isn't really suited for that task as others have already pointed out.

Categories