[Mono-osx] Write to plist

GARRISON, TRAVIS J. garrisot at otc.edu
Tue Mar 22 17:42:54 EDT 2011

Now that I can read successfully, I can't figure out how to write to a plist. I checked the documentation and I can't really find that much info on the NSMutableDictionary, at least on the Set commands.


static bool SetPlistValue(string filepath, string key, string s_value)
                using (var ns = new NSAutoreleasePool())
                                //Connect to Apple framework
                                NSApplication.Init ();
                                //Commented out cause this is a console app
                                //NSApplication.Main (args);

                                //Create a new dictonary to hold our plist
                                NSMutableDictionary plist = new NSMutableDictionary();

                                //Check to see if the plist exists
                                if (NSFileManager.DefaultManager.FileExists(filepath))
                                                //Check to see if the plist has anything in it
                                                plist = NSMutableDictionary.FromFile(filepath);
                                                if (plist != null)
                                                                //return the value for our key
                                                                NSString valueKey = new NSString(key);
                                                                NSString nss_value = new NSString(s_value);

                                                                plist.SetValueForKey(nss_value, valueKey);
                                                                return true;

                                                                //The plist is empty
                                                                return false;

                                //Can't find the plist, correct path?
                                return false;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20110322/9e853c4a/attachment-0001.html 

More information about the Mono-osx mailing list