473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Save List<T> to Settings

Hey guys,

I've been slowly learning C# because XNA Framework looks really interesting. I decided to give software development a shot again. I tried to learn a few years ago but C++ + Win32's API was a pain then.. C# makes things very easy as I love OOP. I'm working on a simple notepad clone w/ childforms. I have a List<ChildForm> which holds all of my forms so I can keep track of 'em.

My question is, how do I save this list into the settings? I want to later, when the program starts up, read the settings and open the last workspace. This way, the user won't have to worry about opening/closing things.

List<T> doesn't show up in the Types in Settings and I tried using ArrayList but it didn't work. I get null errors I can't fix. I tried converting my list to a string, but it didn't work out either...I tried searching, but found nothing that I thought was useful.

I decided to post here as this place comes in many of my google searches with VERY helpful stuff most of the time.

Cheers,
-robodude666
Dec 3 '07 #1
7 3433
Shashi Sadasivan
1,435 Expert 1GB
Hi robodude666,

List<T> is an object type, so if you want to store anything (especially when the same has to be recalled when the application starts up) you have to store it onto the disk.
You can either use text files or a database to store it.

I haven tried storing an object, but to do so you have to serialize it and then stream it to a file to store.
Dec 3 '07 #2
Hey,

Thanks! Based on all my searches, that seems to be the only solution I managed to find. I don't want to really have any extra files except the exe. Is there a way I can save it into the program's AppData folder so that the user doesn't know about this file? Or is there a way I can encrypt the file after writing the serialization to it, so the user won't poke around and edit it?

Thanks,
-robodude666
Dec 3 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
yes, the appdata folder is where you can create files...and store then (best way to distinguish that that folder belongs to that application)

The user can always come and ammend it as they like....
For encrypting it, you would have to encrypt the text before it is written.

But users can still access it, and stil manage to change it / delete it.
Dec 3 '07 #4
Thanks for the quick replies!

How would I save a file to the program's specific AppData folder? I know %APPDATA% is the location for the user's AppData folder, but how do I get to the program's specific program? Is it something like

%APPDATA%/companyname_randomstrip/assemblyversion/

Or does .NET have a specific variable with this address?

How would I encrypt/decrypt a file in C#? I'm new to do ='[
Would the first, or last, class be fine for what I need?

http://www.thescripts.com/forum/thread268041.html

Or is there a better way of doing it? I just want the file to look like gibberish so that if the user does find the file and try to edit it, they won't know what they're looking at and hopefully won't screw it up.

If they do screw it up, is there a quick way to check if its valid before unserializing it? Or would validation come while attempting to unserialize.

-robodude666
Dec 3 '07 #5
Plater
7,872 Expert 4TB
If you wanted, when you wrote out your workspace data, compute a checksum of some kind (there are many variations) and then save that checksum to the settings section.
Then when you load the workspace, re-compute the checksum, if they don't match, discard the workspace file and run like it never had one.
Dec 3 '07 #6
You guys are brilliant! I totally forgot about checksums! I'll try this out later tonight after I finish preparing my presentation thats due tomorrow for class :).
Dec 4 '07 #7
Hey guys,

I've tried serializing the List<T> object like you suggested but I keep getting a "connect convert type" error.. It says i'm converting a blaHelper to a bla type. I did EXACTLY what

http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx

said. Every example I found also gave me the same stuff basically.

Any ideas?

-robodude666
Dec 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Andrew Robinson | last post by:
I have two List<t>. I need to search ListA to see if it contains ListB So: ListA { 1, 2, 3, 4, 5, 6, 7, 8, 9 } Searching ListA with { 4, 5, 6 } would return true and an index of 3....
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
3
by: janzon | last post by:
Hi! Sorry for the bad subject line... Here's what I mean. Suppose we deal with C++ standard integers lists (the type is indifferent). We have a function f, declared as list<intf(int); Now...
2
by: per9000 | last post by:
Hi, *background* I want a class containing an int (a list of sets of integer). This should be hidden for the user and he/she should be able to insert his/her favourite data structure so to be a...
5
by: David Longnecker | last post by:
I'm working to create a base framework for our organization for web and client-side applications. The framework interfaces with several of our systems and provides the business and data layer...
10
by: arnuld | last post by:
It is quite an ugly hack but it is all I am able to come up with for now :-( and it does the requires work. I want to improve the program, I know you people have much better ideas ;-) /* C++...
1
by: shapper | last post by:
Hello, On my MVC projects I often create classes which contains properties which are lists of other classes. Should I start using IQueryable<Tor IEnumerable<Tinstead of List<T>? What are...
2
by: Berryl Hesh | last post by:
Converting in the other direction , IEnumerable<Interfaceto List<ImplInterface>, I can just create a new List<ImplInterface(data) where data is IEnumerable<Interface>. How can I convert the...
6
by: A.Rocha | last post by:
Hi, I need save to text file a List<type>, but i dont wont serialize. // List<mytypemyList = new List<mytype>(); anyone can help me? --
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.