Opening new e-mail form of the default mail client in a WPF / WinForms application
Sometimes, while writing a WPF or WinForms GUI application, you might need to allow the user to send a pre-populated e-mail from her machine. A typical example would be sending an e-mail to your technical support from the application. A naive approach to implement this functionality is to use the following code sniplet:
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("mailto:a@b.com?subject=test&body=xxxxx"));
However this has its limitations. The size of the string you can pass to the ProcessStartInfo’s constructor is limited, therefore if your data doesn’t fit into it, it will be truncated - not very convenient, if you are trying to pass in a long exception stack. You will also have to url-encode the data, which adds to the length of the constructed string and complicates your code.
Use system icons in WPF
Sometimes you would like to use a standard Windows system icon, such as error, warning, question etc. in your WPF program. The main reason is usually consistent look with the rest of the system. While you could have extracted the desired icon from one of the system resource files, there is a much better technique for doing it. First, add a reference to System.Drawing to your project. Then you can use this sample code to get the desired icon quickly:
Safe implementation of INotifyPropertyChanged interface
With arrival of WPF the usage of
INotifyPropertyChanged
interface has expanded dramatically. The most annoying and dangerous part of implementing the interface is, obviously the fact, that you have to pass your option names as strings. This leaves your code prone to bugs - if in 3 months time you rename one of the properties, there is very good chance that you will forget to update the string name as well. In order to overcome the problem we can use some reflection and a little bit of boiler plate code. The good people of the Internet have done all the work for us already, so just copy, paste and enjoy!
Side by side editing of .resx files for localization
WPF allows you to create localized applications with relatively little effort . The localized strings are put into resource files (.resx), one per target language, and maintained as needed. The editing facilities of Visual Studio, however, are not designed to help the localization efforts, however. The GUI can only show one resource file at a time. It would have been much more convenient if files could be edited side by side, allowing easy synchronisation and addition of missing strings. A simple open-source program Simple Resx Editor does just that.
Windows Phone .NET localization that works
I was quite eager to learn about Windows Phone 7 when the development preview came out. I downloaded the tools and tried to build a sample to get a feel. I must admit that developing .NET application for the new OS is quite easy. However one bit I couldn’t make work - localization. With today’s global markets and multi-language consumers it is important to be able to deliver your product in different languages. I suspect there was a bug in the version of software I was dealing with then. Now I have downloaded the latest release and followed this blog entry and it actually worked. This is good news, hope you enjoy it as well.
Microsoft icons for developers
Apparently, Microsoft allows users of Visual Studio to include some icons, supplied with the product. For example, to look at available icons in Visual Studio 2010, locate the file
VS2010ImageLibrary.zip
in the installation directory of your copy of VS (i.e.
C:\Program Files\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033
) and extract the .png files you need. You can extract the necessary sub-images from them.
For convenience, you might consider a free image editing application Paint.NET . In order to be able to save files in .ICO format, you will need this plugin .
Secure storage of passwords in .NET
Storing passwords securely in an application, for instance between different invocations, is a major challenge for a software developer. Storing a password or other sensitive data in plain text is very dangerous. One can attempt to obfuscate the data by means of a symmetric algorithm, but it can be always reverse-engineered from the application.
On Windows there is a safer alternative - DPAPI (Data Protection API). The idea is that sensitive data can be encoded using current user’s credentials. This means, that the data can be stored safely in an encrypted form and will not be compromised until it can be assumed, that the user’s credentials have been not compromised. The API is also accessible in .NET. A simple example, copied from the relevant section of MSDN will demonstrate the principle:
GoDaddy MySQL remote access
Apparently, the well-known hosting provider GoDaddy allows remote access to MySQL databases, created within its environments. Quoting from the help page :
Direct Database Access allows you to remotely manage your hosting account databases with external tools such as Microsoft SQL Server Management Studio Express and MySQL Query Browser. These tools offer a fast connection to your database(s) and additional functionality for advanced users, however, it is a less secure way to manage your databases.
Offlineimap bugs
Offlineimap - a utility, used to synchronize between IMAP servers and Maildir style mailboxes on Unix systems, is very convenient. It can be used to back up your mail, stored on a remote IMAP server. Unfortunately, some releases of the utility are quite buggy - the latest version from the previous maintainer was simply broken, refusing to connect to many remote servers. It appears, however, that there is a new maintainer for the project. The GIT repository can be found here . Caveat emptor.
Samsung Europa Android 2.2 (Froyo) update
Samsung Galaxy Europa i5500 phone is a cheap (around £100 in the UK) and useful smartphone, running currently Android OS version 2.1. An upgrade is expected in the near future to the new, more convenient 2.2 version. However, since this is a low-end model, the release priority is lower than that of its elder sisters, such as Samsung Galaxy S. Therefore there is still no certainty about the exact release date or schedule. We’ll need to wait patiently for the company to make an announcement.