Finding what you need in the Microsoft® Visual Studio® 2005 documentation, which has over 200,000 topics, can be a daunting task. The Doc Detective is here to help, utilizing his investigative skills to probe the depths of the documentation.

Can’t find what you’re looking for? Just ask-if it’s in there, I’ll find it for you; if it isn’t, I’ll let you know that as well (and tell you where else you might go to find it).

Have a question for the Doc? Send your questions for future columns to me at docdetec@microsoft.com.

Dear Doc Detective,

I have some HTML files which I am trying to convert into plain text files. I only want the actual text and not the formatting, so I automatically strip out all of the HTML tags using a regular expression. This works fine, however, some of the text contains HTML “special characters” represented by numbers.

The browser can read the character codes and convert them to the correct character, but when grabbing the text from the HTML file, they show up as the number codes and not the character they represent. I need a way to convert these number codes to the correct characters.

I thought I had found a way using a regular expression

Desc = Regex.Replace(Desc,
"&\#((\+|-)?[0-9][0-9]*(\.[0-9]*)?);",
ChrW("$1")),

but unfortunately it doesn’t work. Can you help?

- Irregular in Irwindale

Dear Irregular,

Your approach to the problem is like using a forklift to move a feather. You don’t need to go the route of regular expressions-the System.Web namespace has a method (HttpUtility.HtmlDecode) that can do the conversion for you. Simply pass it the HTML-encoded string and it will return a string with the readable characters.

You can read more about HTML decoding in the topic “HttpUtility.HtmlDecode Method (String)” in the MSDN Library. And you don’t even need a secret decoder ring!

- Doc D

Dear Doc Detective,

I’m an experienced Windows programmer but new to .NET. I am struggling to discover how to use a timer to assign text to a textbox at regular intervals. I thought I had it, but when I run I get a “Cross-thread operation is not valid” error. Surely it can’t be this difficult to get a timer to work-what am I doing wrong, Doc?

- Timeless in Tillamook

Dear Timeless,

Without actually seeing your code, it’s hard to tell exactly what you are doing wrong, but I can venture a guess. There are actually three different types of timers in the .NET Framework: the System.Windows.Forms.Timer component for use with Windows Forms, the System.Timers.Timer class for server-based timers, and the System.Threading.Timer class for non-UI threads.

If you are using one of the latter two, then the Timer is operating on a different thread than your form, causing the cross-thread error. You can learn more by reading “Running Procedures at Set Intervals with the Windows Forms Timer Component.” Simply switch to the Windows Timer component and your app will be working in no time.

- Doctor D

Dear Doc Detective,

We have a Visual Basic 6 application that we would like to move forward into .NET, but it appears to be a daunting task. I recently downloaded the Interop Forms Toolkit from MSDN, which purportedly allows you to migrate your application one form at a time.

To my dismay I discovered that while it does indeed work well for hosting Windows Forms in a VB 6 app, it doesn’t allow the forms to be used as MDI Child forms. You guessed it-our app is an MDI app! Surely there must be some way to migrate our MDI forms to .NET without having to do a complete migration.

- Dumbfounded in Duluth

Dear Dumbfounded,

You are correct-version 1.0 of the Interop Forms Toolkit didn’t support MDI. Fortunately for you, version 2.0 solves the problem by allowing you to create Interop UserControls-full-fledged Windows Forms controls that you can add to the VB 6 toolbox and drop on any VB 6 form.

For your MDI application you can build an Interop UserControl in Visual Basic 2005, and then drop it on a VB 6 MDI child form and size it to fill the form. In addition to solving the MDI problem, version 2.0 also solves your deployment headaches by providing a redistributable package with everything you need to make interop work.

The Interop Forms Toolkit version 2.0 should be available (for free) on the Visual Basic 2005 Power Packs page on MSDN by the time you are reading this. While you are there downloading it, check out the other Visual Basic Power Packs that are available.

- the Doc

Dear Doc Detective,

I need to prevent my users from running more than one copy of my application at a time. Is there an easy way to tell if they are starting a second copy, then stop them and display a message?

- Controlling in Conshohocken

Dear Controlling,

There is more than one way, and whether or not it’s easy depends on the language that you are using.

If you’re using Visual Basic, you can simply set the Make Single Instance Application project option as described in “How to: Specify Instancing Behavior for an Application.” When the user tries to launch a second instance, the first instance will be brought to the foreground instead.

Once you’ve set the property, a new StartupNewInstance event is fired when the user tries to launch the application-you can add code here to display a message. This is described in the topic “My.Application.StartupNextInstance Event.”

If you aren’t using Visual Basic, you can still check for a running instance of the application by calling the GetProcessesByName method in the System.Diagnostics namespace.

- Doc Detective

Doc’s Doc Tip of the Day

Ever wish you could take it with you? The online version of the MSDN Library often contains updated information that doesn’t appear in your local Help, but that doesn’t help when you are on a plane at 30,000 feet.

A recently released tool named Package This! allows you to choose documentation sets from the MSDN Library to save as HXS or CHM format files. Simply select nodes in the MSDN Library Tree View to package as your own local mini-library, or to build into your own library. An open source application written in C#, you can download Package This! for free from the CodePlex site.

Found a topic in Help that doesn’t help? Tell the Visual Studio documentation team about it at vsdocs@microsoft.com.

URLs

http://msdn2.microsoft.com/en-us/library/7c5fyk1k.aspx

http://msdn2.microsoft.com/en-us/library/aa983620(VS.71).aspx

http://msdn2.microsoft.com/en-us/vbasic/aa701257.aspx

http://msdn2.microsoft.com/en-us/library/8fz4ssw2(vs.80).aspx

http://msdn2.microsoft.com/en-us/library/b9z4eyh8.aspx

http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.getprocessesbyname(vs.71).aspx

http://www.codeplex.com/packagethis