TextBox save value/input automatically - c#

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.

Related

Save user settings for different users in WinForms?

I want to have a save preference option in my WinForms application. The user chooses yes/no and has an option to save preference, upon which the yes/no will be remembered and a form for such a choice will not be popped upon further re running the application.
I read about going to setting and changing but how to do it for different users, since all of them would choose for diff options and I need to maintain that.
Simply using a boolean variable will not help since it will be single user specific. Any suggestions?
(1) At event close main form, you call method/action save result. See How to save data when closing event happen in WinForms?
You can save it to XML file (or text file, SQL lite, SQL Server, etc), popular way is XML file(s).
Read XML file to get saved result before processing business logic in your WinForms application at Load form event or another event type at early stage of application start-up period.
(2) You also save result at previous period in config file https://stackoverflow.com/a/453230/3728901
Properties.Settings.Default["SomeProperty"] = "Some Value";
Properties.Settings.Default.Save(); // Saves settings in application configuration file
So since i didn't want a database , I am creating a file at the client side and saving the preference there.
At run time , I will read from the file and upon that , will decide whether to send form or not .
you can use a Model and store use selected config into it then you should serilaize it and save on database for specific user when reRun the application you can get config and deserialize it to Model and use it

How to save and retrieve program settings when reboot (.NET & C#)

I am building an application where a user can dynamically add buttons at runtime.
However, I am not sure how I should be storing information without having to access a database. I have tried to store it in Properties.Settings.Default, but it does not support Button. Thus, I am using an XML file to store data. Is there any way to save button information (and all the other Controls) when the program terminates, and retrieve when restarted? (instead of using XML)
Edit0: just to make this question easier to understand, here is an example of what I am trying to achieve.
The application allows the user to add a new button and locate them by dragging. Right now, user is able to add new button and relocate it as needed. However, I am unable to save the state so that user can use the same 'layout' when the program restarts. I know that it is possible to save all state in a separate XML file, but this way seems very inefficient.

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

Replace save file dialog opened by any program by a customized save file dialog

I am working on a Version Control/File Sync System for Windows. It would be great to have a checkbox at the bottom of the classical save file dialog with the option to check/uncheck for my file versioning.
Is it possible to listen for opened save file dialogs by any program (word etc.) and replace/override that dialog with a customized one (with an additional checkbox)?
If the checkbox is checked, another window should pop-up where the user could enter some additional metadata. After that the data is stored in a local database.
I already worked with the approach by dmihailescu (link provided) but it's very complex and I do not know how to modify that example to listen for opened save file dialogs by other programs.
http://www.codeproject.com/Articles/19566/Extend-OpenFileDialog-and-SaveFileDialog-the-easy?msg=4779306#xx4779306xx
Another approach is to use the FileSystemWatcher but that's very expensive to watch the whole system and it's not very comfortable because the user has to be asked for any created file if he/she wants to version control it.
I hope someone could help me to solve that problem or has some additional tips / approaches.
Thank you.
Edit: Use-case
A user has to write a documentation and creates a new word-doc. When he/she clicks the Save as menu entry of word, my customized save file dialog should pop-up with a checkbox at the bottom, if this file should be versioned or not. If the checkbox is "active" a new window should appear where the user could enter additional metadata. After that the data should be stored in local database.
In my case, only the metadata (like the path etc.) should be stored in the database. Let's suppose a user stores the same file in two different directotries (one file is "older" and one file is the current one). If the user opens an older version of this file, my system should recognize that a "newer" one is already stored in another place and synchronize those files.
That should just be a very easy example.
You have two pieces of functionality: save and version-control. Both of the tasks are actually rather complicated. Therefore you shouldn't mix them. You better off using standard Windows API to save file and do not change that. Think about how you'd support several different Windows releases and how painful that would be.
I assume you have your own UI, and do not integrate with, say, Windows Explorer (like Tortoise Svn or Dropbox). In this case you can do version-control magic first and then just save the end file using standard API.
If you do integrate with Windows Explorer, I suggest you to have a look at Tortoise svn source code.

Categories