I'm currently working on a winforms application that gets information from a user via a textbox. Since this information is not likely to change very often, I would like my application to save the input and load it into the appropriate text box the next time it is run.
I feel confident in my ability to set this up on the form side of things, my question has to do with how to store the values outside of the program. My first instinct is to just use a text file, but the overhead needed to handle IO and reading in the values seems a bit much. I also would rather not have the user editing it outside of the textbox in the program. I tried using string resources, but those are read only. Is there a more elegant solution available?
You need at least a mediocre database client whether it be sql server, mdf, MS Access, SharePoint, Oracle etc. Sounds like a vis studio prog. (winforms). They are designed for IO procedures but requires data architecture knowledge or relational dbs. (RMDBS). Try a lightswitch project (if a VS proj.) to get the basics of db and form data relationships.
I know it's not outside Your program, but you could try settings, it's easy, kinda like the resources ownly in the settings you can change it.
To change settings goto:
Properties and then double click Settings, here you van add strings, bools etc. Make sure you set them to user
To access them through code use:
Properties.Settings.Default.
To save the settings use:
Properties.Settings.Default.Save()
Related
I'm totally new to C#, and got an assignment building a WPF form to modify settings in an existing C# program using Visual Studio and WPF.
I have numerous goals:
Get a list of all of the Settings names.
Retrieve all of the user properties.
Add a line for every setting to the form, and allow the user to restore the original settings, use the current ones, or modify them to a new value.
Make sure that the user input is in the correct Type.
Bind between the TextBox and the values in the line, not sure what is the best way to send the details. What object do you recommend to bind to the xaml? The list containing the property lines? Or to bind every line separately?
I think that I need to access the App.config file for 3, so far unsuccessfully. I would have like to get an advice about the architecture, since I'm new to VS, C# and WPF.
I don't think this is an assignment suitable for someone new to wpf let alone c#.
Even experienced wpf developers are likely to find some tricky bits in this task.
app.config will be in the same folder as your exe. If that is in program files then you will not be able to edit and save. Unless your users are win 7 or earlier.
User settings will usually be stored in appdata for this reason. Since the user is expected to likely want to change them.
They go in a user.config file. The location of one off my system is:
C:\Users\Andrew\AppData\Local\MapEditor\MapEditor.exe_Url_aszfdqs5110y44xmg0kfuuqbatf5la5a\1.0.0.0\user.config
I am user Andrew on the machine and these are the user settings for MapEditor.exe.
The file itself is xml.
In there I see
And there's a bunch of stuff inside that.
I would not try and edit xml directly.
And this is your first bit you'll find isn't exactly easy.
Because you need to translate xml.
"All the user properties."
You presumably know what they are.
Because the user can't just add them.
They need to be defined in the app.
I'd pick out the pieces you want them to change and copy data to a viewmodel. Or observable collection of viewmodels presented by a parent viewmodel.
Probably simplest as an observablecollection.
You can then have a different viewmodel class per type of property.
They enter a string in a number then it'll fail to transfer back to the viewmodel and you can trap validation.errors that'll bubble.
To save, translate the viewmodels back into xml and save it.
I am working on cloud storage system in ASP.Net MVC5. In which I made a file manager that handles cut,copy,download multiple files,edit and preview of files, but I want to edit documents like word files in real time (collaborative editing)..is there any api that can help me accordingly.
Thank you in advance.
you should use Signal R for real time applications...it may be possible with the help of application user interface but its better to write your own code according to your choice...
[http://signalr.net/][1]
dev_express and syncfusion may be your solution..try these..
This is turning into a huge comment, so I'll just explain my point of view in an answer. I'll remove it, if I see an actual answer appears.
I am suggesting you start writing your own code for collaborative editing and the reason is quite simple. You need at least slightly different processing for almost each file type, which suggests there will never be a single API to support collaborative editing for all file types, unless somebody makes it their goal to maintain it and keep up with every one created.
Start it simple, text (or hex) editing. Define how changes are made and implemented on other clients and then work your way to add as many file types (and methods that go with them) as you need.
You could use source code of 1 of these open source collaborative text editors (you'll have to find download / Github links on their websites) to get a general idea how to do it, but you will still have to put in some work and won't go far without creating your own code.
Collaborative editing requires user 1's (who just started editing) client to send either one of these:
Data pointing to changes made in file
Full file, and user 2's client (or central "server") should be able to calculate the changes made from there and implement them.
One of the problems is to overwrite only that portion of the file changes were made to (and avoid overwriting the other user 2's work).
And the biggest problem (the reason you can't have "1 for all" method/API) is each file type has its own structure meaning that different file types will have different data representing changes in file. If you try to write raw data it might work, but you'd still need to calculate and lock away specific portions of file, that contain general information, rather than data of your file.
I am learning C# using Visual Studio and I am running into some issues.
I am developing a Windows form application. The application is meant to track user's running stats.
In settings: they select how many days they run and for each day they add their workout (ie: 1: 100m sprints 2: 50m sprints 3: Run a mile).
Then in the main windows form the user will be able to add their times and save it. Meanwhile a graph is projected of their times- this will allow the user to track their progress.
My question is where should I store their times? Right now I store all settings in the settings.settings doc. For the times should I use the settings file or a SQL database of some sort?
SqlCE or SQLite or any other simple inproc database will be better than Settings file.
Settings are not meant to grow with every user input, this is a task for a database, also it will be much easier to query your data using SQL.
Answering your question in comments:
There is a difference between user data and user preferences. You have to decide which is what in your app.
I would go with Settings file with everything regarding user preferences. Like form layout, colors, sounds, window size and so on.
Since Settings managing framework is pretty sophisticated, you will save yourself some time designing tables for user preferences and developing access to that tables.
Another possibly bright side of Settings file - it can be edited manually with text editor.
It is not possible to answer you without a lot more information about what a "user's running stats" is and how it is used. I can give a few general guidelines, though.
System.Configuration.ApplicationSettings are designed for customizing an application for a specific user; for example, what language the user wants the application to use, where he wants windows to appear, or default values. Settings are part of the application; they are created when the application is installed and deleted when the application is uninstalled. If multiple users run the application, each typically gets their own settings. You typically define settings when you create the application and users never add or remove them.
Databases are used to persist user data. They are typically not tied to a specific user or application; users add the data, which is available to other users or applications. Applications typically aren't installed with all user data, nor is user data deleted when the application is uninstalled.
SQL databases are used for relational data; data that has internal structure, like "all users must have exactly one address", or "any user may have zero or more phone numbers". If your data is not relational you do not need a relational database.
These are general guidelines, specific applications may do things differently for specific purposes. If you tell us more about your application we will be able to provide more specific information.
I'm just starting to work with windows 8 development (using c#), and am working on porting one of my applications to a windows store app. Essentially my application takes a user input string, calculates an appropriate output, and responds to the user. So I'm using a list view to track the "conversation." I display the user's input as a list view element and then display the output as the next element (using text blocks with formatting like color...).
What I would like to do is make this "conversation" persist once the app is terminated but am not sure the best way to do this. My first thought was to serialize the list view object on suspension then deserialize it on load, but the listview isn't serializable...So my next thought was to write out each input and output string to a file and try to rebuild the listview from these strings when I load the application, but I am having some issues with this as well.
So I'm curious as to what the best way to go about this is. I would like the application to start back up with the previous conversation already displayed with the same formatting and what not. Does anyone have any ideas?
I wouldn't persist the ListView anyway, you only need to persist the data in it. Are you using a MVVM type model, where your conversation is perhaps captured as an ObservableCollection and then bound to the ListView? If not, you should :)
Then you'd just need to serialize the ObservableCollection (see one option for that here). Where you persist it kind of depends on you:
LocalFolder would use a file based approach and be available on the local device
RoamingFolder would also use a file based approach but sync using the cloud across multiple devices that the user owns (and has the app installed)
Cloud storage (like Windows Azure or Windows Azure Mobile Services) would provide essentially boundless storage for you, but requires managing a cloud account and paying for it (though free tiers may be sufficient)
An in-memory database like SQLite is yet another option and would give you relational semantics should that be interesting to you.
To get started, I'd say use LocalFolder and persist your collection to a file, then when you rehydrate it, simple data binding should automatically handle the display. At some point, you may need to make a decision about how much to store. You want your application to be responsive for the user ('fast and fluid'), so to that end you may need to bring in data as it's requested versus all at once (perhaps a version 2 feature!)
If I want to add a string as a setting or an image as a resource – I do it through Visual Studio.
But how do I add something complicated such as a large array or a Form which has to first be computed at runtime (or in case of the Form – populated with controls)?
I thought I could run it and persist it in settings (Properties.Settings.Default.Setting1 =...), and then publish. But that doesn't work (See: How to persist from build programmatically? ).
So how is it done?
Have you read up on serialization? I know that's kind of a generic answer, but I hope it helps.
As for a large array, you need to come up with an approach or mechanism for storing the data.
If it's a simple array that won't change very often, you can store it in the app.config.
If it's a datasource (ie: the data changes often) you could use an XML file and ideally a database.
I'm not really sure what you mean by persisting a Form. A Form should contain all controls compiled within it's own executable or dll. If you are asking how to populate the form, you would do this in the Main() method of the main form.