Here’s a code snippet i just found really usefull. I was getting 20 MC75 pda’s ready for a customer pilot project and we’ve developed a solution but hadn’t design any deployment system for getting the devices ready, so it was all manual work.
The solution uses the network through GPRS/Edge and each of the devices needed to have a cellular (GPRS) Line modem connection defined. Doing this on 20 devices by browsing to Settings -> Connections -> Add new modem connection, then add the same data for APN, username, password was just to much of a pain.
An easier way of doing this is to use the ConfigurationManager, found in the Microsoft.WindowsMobile.Configuration namespace. My purpose was to just make sure there was a cellular modem connection defined with a working configuration. I wanted this to be the first to be done, and i wanted this to be re-run at application launch each time to reset any “mis”-configuration done by end users thorough the pilot period.
Firstly i defined a method that would give me a string with xml data. – This could also have been done a bit more elegantly or smooth, but it works for me this way.
private static string XmlConnectionString()
{
string connectionName = "GPRS";
string username = "";
string password = "";
string apnName = "Telenor";
string myString =
"<wap-provisioningdoc>" +
"<characteristic type=\"CM_GPRSEntries\">" +
"<characteristic type=\"" + connectionName+ "\">" +
"<parm name=\"DestId\"" +
" value=\"{ADB0B001-10B5-3F39-27C6-9742E785FCD4}\" />" +
"<parm name=\"UserName\" value=\" "+ username +"\" />" +
"<parm name=\"Password\" value=\"" + password +"\" />" +
"<parm name=\"Domain\" value=\"\" />" +
"<characteristic type=\"DevSpecificCellular\">" +
"<parm name=\"GPRSInfoValid\" value=\"1\" />" +
"<parm name=\"GPRSInfoAccessPointName\" value=\"" +
apnName +"\" />" +
"</characteristic>" +
"</characteristic>" +
"</characteristic>" +
"</wap-provisioningdoc>";
return myString;
}
Secondly I create my modem connection as the very first thing in the application Main method.
[MTAThread]
static void Main()
{
try
{
XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(XmlConnectionString());
ConfigurationManager.ProcessConfiguration(configDoc, false);
catch (Exception ex)
{
// Error Handling.....
}
}
This was a quick and “dirty” way of doing it, and it saved me some time.