When you operate with downloads on a Windows Phone 7 device, chances are that the volume of the content to be downloaded will vary. This might cause some issues especially for cases when the download is controlled by the user and not by the developer (therefore the user is able to arbitrarily choose any file to download).
For example, what would happen if the end user decides to download a 4GB file while connected to his cellular data network? Most likely, you don’t want to allow this since there could be bandwidth problems.
To limit the usage, you might want to detect the type of network connection first of all. To do this, there is the NetworkInterface class (member of Microsoft.Phone.Net.NetworkInformation) that exposes the NetworkInterfaceType property. This property represents the type of network connection that is currently used by the Windows Phone 7 device.
You can get the complete list of possible connection types here.
You can check the current network interface by simply calling the property, without explicit class instantiation:
Prior to this, you might want to check whether any network connection is available, via:
When you run this code in the context of the Windows Phone 7 emulator, the network interface used by Windows will be considered to be the default one. So, for example, if I connect to the Internet via a wireless link, the result will be:
In case the device is using a cellular data network, it can return this for GSM networks (for example, AT&T):
And this for CDMA networks (for example, Verizon):
When you check for this property, you can easily decide whether you want to allow a certain download to be started or not.
Finally, you can us this property for many other application modules. For example, you could limit specific functionality only to GSM or WiFi connections, like VoIP calls.