Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to store a string array in my program so it can be retrieved every time the program starts...
is there any method other than storing the array in a text file???

thanks,
Posted
Comments
BillWoodruff 18-Sep-11 3:30am    
A good question, but it would be helpful if you would carefully tell us in your questions what solutions you want and don't want: I had to read this entire thread to find out that you don't want to write a file using any technique. best, Bill

You can use the BinaryFormatter to serialize an object containing your array.
This will create a binary image of your object which you can write to a binary file.

MSDN BinaryFormatter
 
Share this answer
 
Comments
George_Rasmi 17-Sep-11 14:37pm    
I don't want to write on a file ... I just need to store it inside the program like (Properties.Settings ...etc)
can you help me???
thanks,
If the values in the array is fixed and it's a small utility program you can store it in the code itself as an array variable. Otherwise if you know it may get modified by the user you may choose either a separate text file, a resource file (.resx) or store as configuration data in the DB.
 
Share this answer
 
you can (ab)use the windows registry for this
 
Share this answer
 
Comments
Mehdi Gholam 17-Sep-11 14:21pm    
My 5! overlooked the simplest!
George_Rasmi 17-Sep-11 14:38pm    
Actually, this is not what I'm looking for :(
anyway, thanks digimanus :)
Hello,

You could use Isolated Storage:
http://msdn.microsoft.com/en-us/library/x7dzh4ws.aspx[^]
http://msdn.microsoft.com/en-us/library/3ak841sy(v=VS.100).aspx[^]

There is plenty of samples available:
Isolated Storage in .NET to store application data[^]
Use of Isolated Storage (A Simple Demo)[^]

Basically to use it you would do something like:

C#
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
// to save data
appSettings.Add("myData", "blah blah blah");
// to read data
string data= (string)appSettings["myData"];


Valery.
 
Share this answer
 
v2
Check this code
Create one settings named MySettings with Type System.Collections.Specialized.StringCollection in settngs window

Save your settings
// Create and initializes a new StringCollection.
           StringCollection myCol = new StringCollection();

           // Add a range of elements from an array to the end of the StringCollection.
           String[] myArr = new String[] { "RED", "orange", "yellow", "RED", "green", "blue", "RED", "indigo", "violet", "RED" };

           myCol.AddRange(myArr);
           Properties.Settings.Default.MySettings = myCol;
           Properties.Settings.Default.Save();



Getting it from settings

StringCollection myCol2 = new StringCollection();
            myCol2 = Properties.Settings.Default.MySettings;


hope it helps
 
Share this answer
 
v2
Comments
BillWoodruff 18-Sep-11 3:28am    
+5 interesting answer. I've never even looked at the System.Collections.Specialized library, but I will now, thanks. best, Bill
George_Rasmi 18-Sep-11 6:20am    
This is exactly what I'm looking for :)
thanks arunkumaraymuo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900