Log in

View Full Version : Save User Settings - Windows Mobile 5.0 Pocket PC


JohnHappy
02-07-2006, 07:37 PM
Developing my first Windows Mobile 5.0 Pocket PC app using VS 2005. The app needs to be able to save a string of up to 10 characters as a 'user setting' so it is available the next time the app is opened. The user needs to be able to modify the string as well.

I've seen stuff about app.exe.config files and creating an XML file but haven't found anything yet that helps me understand about creating a 'using settings' solution for a Pocket PC running Windows Mobile 5.0.

Please help me understand how to use VS 2005 to save user settings for a Pocket PC device running Windows Mobile 5.0.

Guest979
02-08-2006, 04:01 AM
I don't think .NETcf (the compact framework version for PPCs) supports the static methods in System.Configuration.ConfigurationSettings that full-size .NET programs can use (like GetConfig and AppSettings).

There is an almost infinite number of other options:
1) Get SOAPy (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceoak40/html/coorisoaptoolkitoverview.asp)
2) Check if someone has a downloadable library with an XML parser you can use or compile 8O
3) Write your own XML parser 8O 8O 8O
4) Just spew the string out to a plain-old file, since XML is overkill for storing one string. Example:

using System.IO; //Add to your other Using statements if it's not already there

//....

String saveMe = "Best string ever!";

StreamWriter sw = new StreamWriter("MySettings.txt",false); //False indicates that you will overwrite an existing file rather than appending to it

sw.WriteLine(saveMe);

sw.Close();

StreamReader sr = new StreamReader("MySettings.txt");

String whatIRead = sr.ReadLine();

sr.Close();

if(saveMe.Equals(whatIRead)){
System.Windows.Forms.MessageBox.Show("Yay, it worked.");
}else{
System.Windows.Forms.MessageBox.Show("Please incinerate this PocketPC.");
}
//.....

(Note: untested at present, may have minor errors.)

JohnHappy
02-08-2006, 07:35 PM
Thanks for your help.

The StreamWriter / StreamReader solution works fine.

Guest979
02-09-2006, 08:48 AM
You're welcome. I should've clarified that the above code is in C#, which is actually not the only language you can use with .NET/.NETcf. I don't know Visual Basic very well, but it is supposedly pretty easy to translate. And as for using C++ with .NET... it's quite difficult at times (shudders) - I think C++ was originally designed with certain assumptions in mind (like not having automatic garbage collection) that aren't the norm for .NET.