65.9K
CodeProject is changing. Read more.
Home

Using the VB.NET My Namespace in C# .NET 2.0

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.05/5 (9 votes)

Jan 20, 2006

CPOL

2 min read

viewsIcon

74864

downloadIcon

404

In VB.NET 2.0, we have a new namespace, My, that exposes some nice classes. This article shows you how to access this namespace in C#

Introduction

I just happened to run across this in a Visual Studio 2005 help file.  I had seen all the hype for VB.NET 2.0 with the new My namespace, and I thought that might be nice to use in C#.  This article follows the simple steps I found in the Visual Studio help file to do just that.

Background

You might ask why I was looking through the Visual Studio 2005 help files?  I was reading up on some topics that I thought would help me be a little more ready for the next Microsoft certification upgrade tests.  Anyway, I was looking through the namespace help just to see if there was anything interesting.  I ran across this example and thought I would write an article on it so others could benefit.

The Code

It is really quite simple.  First you need to add a reference to the Visual Basic Library.  I know it makes me a little nervous too.

Adding a reference to the Visual Basic dll

Next, add a using clause:

using Microsoft.VisualBasic.Devices;

Finally use the MyServices namespace:

Computer myComputer = new Computer();
myComputer.Audio.Play(@"c:\WINDOWS\Media\chimes.wav");

There are quite a few cool things (classes) in the namespace. Here is a short list:

  • Audio
  • Clipboard
  • Clock
  • FileSystem
  • Info
  • Keyboard
  • Mouse
  • Name
  • Network
  • Ports
  • Registry
  • Screen

NOTE

The help file mentions that there are some classes that were not compatible.  The example they gave was FileSystemProxy.

The link to the help file is: ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/e7152414-0ea5-4c8e-bf02-c8d5bbe45ff4.htm.

The title is: C# Programmer's Reference
How to: Use the My Namespace (C# Programming Guide)

Conclusion

So I hope you find this useful.  I don't think I will be using this in every project, but it is nice to know that you can do it when you need to.

History

  • 20th January, 2006: Initial post