Archive for February, 2011

How to use the My Namespace in C#

February 22nd, 2011

When I was first trying to transition from VB.NET to C# I found it pretty odd that the “My” Namespace wasn’t available in C#.  If you aren’t aware of what I’m talking about, the Microsoft.VisualBasic.MyServices namespace (My in Visual Basic) provides easy and intuitive access to a number of .NET Framework classes, enabling you to write code that interacts with the computer, application, settings, resources, and so on.

After a little hunting I discovered that by simply adding a reference and a using statement that I could be up and running with my beloved My classes that I had come to know and love.  Here’s how you do it…

Add a Reference

  1. In Solution Explorer, right-click the References node, and select Add Reference.
  2. When the References dialog box appears, scroll down the list, and select Microsoft.VisualBasic.dll.You might also want to include the following line in the using section at the start of your program.
    using Microsoft.VisualBasic.Devices;

Example

This example calls various static methods contained in the MyServices namespace. For this code to compile remember that we added a reference to Microsoft.VisualBasic.DLL in the step above.

using System;
using Microsoft.VisualBasic.Devices;
 
class TestMyServices
{
    static void Main()
    {
        // Play a sound with the Audio class:
        Audio myAudio = new Audio();
        Console.WriteLine("Playing sound...");
        myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");
 
        // Display time information with the Clock class:
        Clock myClock = new Clock();
        Console.Write("Current day of the week: ");
        Console.WriteLine(myClock.LocalTime.DayOfWeek);
        Console.Write("Current date and time: ");
        Console.WriteLine(myClock.LocalTime);
 
        // Display machine information with the Computer class:
        Computer myComputer = new Computer();
        Console.WriteLine("Computer name: " + myComputer.Name);
 
        if (myComputer.Network.IsAvailable)
        {
            Console.WriteLine("Computer is connected to network.");
        }
        else
        {
            Console.WriteLine("Computer is not connected to network.");
        }
    }
}

Not all the classes in the MyServices namespace can be called from a C# application. You can visit this MSDN article that details more on what’s not supported.

Use ASP.NET and DotNetZip to Create and Extract ZIP Files

February 16th, 2011

I recently came across this article from Scott Mitchell, that shows how to use DotNetZip to create and extract ZIP files in an ASP.NET application, and covers advanced features like password protection and encryption.

The article details all that you can do with the feature-rich, free, open source ZIP implementation for .NET - DotNetZip. Using DotNetZip and a dash of .NET code you can:

  • Create a new ZIP file and add one or more files or folders,
  • Read the contents of a ZIP file,
  • Extract all (or some) of the contents of a ZIP file to a specified folder,
  • Use advanced ZIP file format features, such as encrypting the contents of the ZIP and protecting them with a password.

This is definitely something that will come in handy.  I’ve tried working with zip files in the past and it has never been this easy.  Dealing with a ZIP file is definitely something that you will need to do at some point if you program long enough.  With this article, it will definitely be something that you won’t bang your head against the wall trying to accomplish!

ProClip, the BEST iPhone mount you can find!

February 15th, 2011

My 2010 Toyota Prius is a great car!  It’s a geek’s dream with all the hi-tech bells and whistles it has.  For example, I use the Bluetooth integration in the car quite a bit for both talking on the phone and audio (music, podcasts, etc).  With the phone being the main source for audio entertainment, there are many times I need to access it while driving (change a song, fast forward through a podcast’s commercials, etc).  Unfortunately, half the time I needed it my phone it had slid off the passenger seat where I had it plugged in charging or was out of reach.

The only usable factory option was the cup holder in the center console but most of the time I have my coffee or water in there.  I researched various options and could never really find a good way for my iPhone to sit while I was driving, especially when I had a beverage in my cup holder.  Unfortunately the Prius’ design doesn’t really lend itself to the traditional vent or window iPhone mount.

Finally the other day I stumbled upon the ProClip website and realized there was still hope.  ProClip had a proprietary two part system that looked legit and that seemed perfect for how my Prius was laid out.  I ordered the item and it arrived in just a few days.  After a quick 15 minute install I must say that I’m glad I pulled the trigger on the ProClip.  Like I said, the system has two parts.  You first install the base mount and then you get your device specific holder (my links are to the specific parts I ordered for my 2010 Prius).

If you look around you’ll see there are numerous options for the device holder with various prices.  I opted to get a slightly more expensive one that had a pass-through for the phone charger, just so I didn’t have to hook that up each time I put the phone into the mount (yes, I’m that lazy).  If you want to spend less money there are options there for you when it comes to the device holder.  The mounts are more cut and dry (vent mount, console mount, etc).  That really depends on where you want it to be.

So far the holder has been great.  I was able to have my coffee in my cup holder, my phone angled where I could easy see and control it, and everything seemed solid.  I do have to get used to getting the phone in and out of the holder, but I think that’s something that will get easier over time, and the holder will get broken in allowing the phone to slide in and out without much effort.  The holder is padded and has a very good quality finish.  I can tell it will never scratch the phone or allow the phone to fall out.  And while I haven’t used it, it supports both vertical and horizontal modes.

If you’re looking for a decent mount for your iPhone, and you don’t mind a more permanent option, definitely consider the ProClip mount!

My Must Have Jailbroken iPhone Apps

February 9th, 2011

The iPhone 4 is an awesome smartphone.  It truly has started to replace my desktop and laptop computer for many day to day tasks.  While Apple did a good job at making this phone very user friendly and functional, you can really make this tiny little pocket computer even better without much effort.  Jailbreaking your iPhone will really unleash this device’s true power and will fix/help the few flaws and/or limitations that Apple, or your carrier, has placed on this device.

Since I recently updated my phone to the latest iOS version, 4.2.1, I figured I’d share with you the latest tool I used to jailbreak the phone and the few of my “must have” jailbroken apps.  I won’t go into much detail about how to install the jailbreak or each individual app, there are plenty of resources available on the topic.  I just wanted to share which apps I have come to love and depend on, which have made me love my iPhone even more.

First, Jailbreak it (Guide for Windows, Mac).

Second, the apps…

My3G

Facetime over 3G! Take back your 3G! My3G makes Apps believe that they are on WiFi instead of 3G. With My3G, you can now watch HiDef YouTube videos, use Skype/Fring/Other VOIP apps over the 3G network!

MyWi 4.0

Create an iPhone WiFi HotSpot or iPad WiFi HotSpot with a press of a finger! Wherever you are – you can connect your laptop or other mobile device to your iPhone/iPad easily to use your iPhone/iPad’s data connection.

Wi-Fi Sync

Wi-Fi Sync enables wireless syncing with iTunes at the touch of a button. Never go looking for that USB cable again. Sync from the car, bed or shed whenever it suits you.

LockInfo

Gives you access to your information where you need it, when you need it. You can view your new emails, upcoming calendar events, unread SMSs, missed calls and much more on your lockscreen.

biteSMS

Takes all of the basic features of the built-in Messaging app, and adds many more great features.

SBSettings

Offers a faster method to manage iPhone settings like rebooting, turning on/off Wi-Fi, 3G, Bluetooth, etc.