Day of .Net Presentation

I thoroughly enjoyed my presentation and the time at Day of .Net this past Saturday. Special thanks to those folks who attended my presentation.

Here is my slide deck.

This is a zip file of the code from the presentation. Remember you need the .Net 3.0 framework and the SDK for Open XML Formats CTP in order to run the code.

Posted: Monday, October 22, 2007 4:30:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | Speaking

Open XML References

Resources

ECMA-376  Standard Specification

Word 2007 Content Control Toolkit

Open XML Code Snippets for Visual Studio 2005

OpenXmlDeveloper.org

Open XML e-book

XML in Office Developer Portal

SDK for Open XML Formats CTP (online)

MSDN Forum for Open XML SDK

Software

Package Explorer

ExcelPackage

Word 2007 Content Control Tookit

Open XML Code Snippets for Visual Studio 2005

SDK for Open XML Formats CTP (download)

Microsoft .Net Framework 3.0

Articles

Introducing the Office (2007) Open XML File Formats

Building Server-Side Document Generation Solutions Using the Open XML Object Model (Part 1 of 2)

Building Server-Side Document Generation Solutions Using the Open XML Object Model (Part 2 of 2)

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 1 of 2)

Manipulating Excel 2007 and PowerPoint 2007 Files with the Open XML Object Model (Part 2 of 2)

Dive Into SpreadsheetML (Part 1 of 2)

Dive Into SpreadsheetML (Part 2 of 2)

Manipulating Word 2007 Files with the Open XML Object Model (Part 1 of 3)

Manipulating Word 2007 Files with the Open XML Object Model (Part 2 of 3)

Manipulating Word 2007 Files with the Open XML Object Model (Part 3 of 3)

Blogs

Wouter van Vugt

Brian Jones

Kevin Boske

Posted: Friday, October 19, 2007 6:24:25 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | Speaking

ASP.NET Web Project Build Events

I have a web project (the original 2005 web project type, not a web application project) and had a problem getting files copied to the bin directory. Essentially, one of the library projects referenced by the web project has an XML file in the project output, but when the solution is built, the XML file in the bin directory of the library project is not pulled into to the bin directory of the web project. Of course, a post-build event seemed like the thing to do, but web projects don't have support for that.

A little digging and I found this post by Scott Guthrie that describes a "Build Helper Project". You simply add an empty class library project to your solution. You then use the build events in the empty project use to add build events to your web project. You just make sure the project build order is correct so the events get called when you need them.

Posted: Monday, October 08, 2007 4:28:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | ASP.NET

Speaking at Day of .Net in Ann Arbor

I will be speaking at Day of .Net in Ann Arbor, MI on October 20th. It's a Saturday, and it's a completely free event. I will be presenting Creating Office Documents with Open XML. I will be going over the Packaging API and how to programmatically create and manipulate Office docs.

There are four concurrent sessions all day long covering many aspects of .Net.

See you there!

 

Day of .Net October 20, 2007 - See You there!

Posted: Thursday, October 04, 2007 5:03:49 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | Speaking

Laws from DDJ

Got my new November Dr. Dobbs issue today. The back column "Swaine's Flames" has reminded me of some programming "laws" that I have seen before. I have added my own corollaries for each:

Kernighan's Law: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

My corollary: "The developer who's code that you inherit believed they were twice as smart as they really are."

Eagleson's Law: "Any code of your own that you haven't looked at for six or more months might as well have been written by someone else."

My corollary: "You can recognize that you have written code to solve a particular problem but will be unable to locate the specific instance you recall."

Posted: Tuesday, October 02, 2007 4:50:05 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Programming

Links for VSTS Database Professional Edition

Resources

Team Site
http://msdn2.microsoft.com/en-us/teamsystem/aa718764.aspx

Product Forum
http://forums.microsoft.com/msdn/showforum.aspx?forumid=725&siteid=1

Good Blogs
http://blogs.msdn.com/camerons
http://blogs.msdn.com/sachinre

 

Downloads

Service Release 1
http://support.microsoft.com/kb/936612/

PowerTools
http://go.microsoft.com/fwlink/?LinkId=88852

Posted: Tuesday, September 25, 2007 5:00:06 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio | VSTS

Day of .Net in Ann Arbor, MI

Registration is now open for Day of .Net in Ann Arbor on October 20th, 2007 at Washtenaw Community College in Ann Arbor, MI. Register here for this completely-free, all day learning event. Start planning now to take advantage of this event!

Day of .Net October 20, 2007 - See You there!

Posted: Tuesday, September 11, 2007 3:40:49 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback

Use RunAs to Connect to SQL Servers in Another Domain

Doh! Another simple thing I wish I knew (or thought of) previously: Using RunAs to connect to SQL Servers in other domains

Posted: Friday, September 07, 2007 4:31:07 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

ASP.NET 404 Errors on the Default.aspx Page

On a new server install, you can copy over the files for your web app and mysteriously get 404 errors. It's a simple configuration in IIS. By default the server is configured not to allow ASP.NET. You simply need to enable this in the IIS management console:

Posted: Wednesday, August 29, 2007 11:36:10 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | IIS

Caching Images in IIS 6.0

Yahoo posted a list of rules for improving the performance of your web site, along with a new FireFox-based tool for diagnosing your site's performance, called YSlow.

Their number one rule is to reduce the number of HTTP requests, and this only makes sense. I'll bet most of us ASP.NET developers are well aware of output caching, and how to do this in code. But what about those static files, like images and scripts? Well, there is an IIS setting for that. It's easy to do, and the payoff can be big if you have a very graphic-intense site. Here's what you do for IIS 6:

  1. Open the IIS Management console
  2. Find the directory containing your images (static content only)
  3. Right click the directory, and choose Properties.
  4. Click the HTTP Headers tab.
  5. Check the Enable Content Expiration check box.
  6. Click the Expire After radio button, and choose an interval.
  7. Click the OK button. Done!

The downside is that you won't get the payoff for the first time a user visits the site, but other pages using the same resources will be much snappier. Be aware that caching dynamically created content this way can cause some strange issues, so take care as to what you cache. As always, test it well before you release it and you will be rewarded.

Posted: Monday, August 20, 2007 4:11:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
IIS | Performance

Speaking at West Michigan Dot Net User Group - WCF

I will be speaking on July 17th on Windows Communication Foundation. See the West Michigan .NET Users Group site for details.

Posted: Saturday, July 07, 2007 9:59:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 3.0 | Speaking | WCF

Web Services Authentication Gotcha

We had code in an ASP.NET page trying to call the Commerce Server Profiles web service that resides on the same physical box. The credentials we used were appropriately configured for Commerce Server using AzMan. For some reason, the code was failing with a 401: Unauthorized error. No matter what credentials we used, no luck. But if you ran the code from another box, it worked fine. Same credentials pointing to the service on that box, no errors.

Turns out the hosts file had an entry for the DNS name we were using, and mapped that name to 127.0.0.1, the loopback address. This was the gotcha. Apparently there is a loopback security feature that causes this behavior. There is a support article describing the effect. Essentially it is a security check to keep certain kinds of attacks at bay. The article suggests registry changes to disable it, but we took a different route.  In the short term, if the calling code accessed the web service via IP address (NOT 127.0.0.1) instead of DNS name the problem was circumvented. Meanwhile the network guru is working to get the actual DNS resolution to work.

Posted: Tuesday, July 03, 2007 11:45:21 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Commerce Server | Security

Sql Server Fix Logins

Sometimes when copying databases, for instance from production down to development, the user accounts become dysfunctional. The database login no longer matches the overall server login. To re-synchronize them use:

exec sp_change_users_login auto_fix, 'someusername'

Posted: Tuesday, June 05, 2007 10:12:17 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

Even More WCF Links

Articles by Juval Lowy

Aaron Skonnard's Wiki

WCF Developer Center on MSDN

Posted: Friday, May 18, 2007 5:54:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 3.0 | WCF

Speaking at West Michigan Day of .Net

I will be speaking at the West Michigan Day of .Net on May 19th in Grand Rapids, MI at Davenport University.

My talk is Introduction to WCF. WCF is certainly the understated pillar of .Net 3.0. There is a ton of great content all day long, and best of all it's FREE! This is a great opportunity, don't miss out.

WM Day of .Net May 19, 2007 - I'll be there!

Posted: Tuesday, April 10, 2007 3:57:09 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | WCF

More Good WCF Links

The Server Side .Net has a good WCF link aggregation.
Posted: Wednesday, April 04, 2007 3:48:30 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
WCF

More SelfSSL Issues

I blogged previously about some issues with SelfSSL and multiple web sites. A colleague of mine, Charles Medcoff, blogs about a related problem with SelfSSL and SQL Server.
Posted: Wednesday, March 28, 2007 4:39:17 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Security | SQL Server

WCF Presentation

I am giving a presentation March 15th at the Greater Lansing User Group .net about Windows Communication Foundation.

If you have worked with web services at all you will really appreciate WCF. Come by and check it out.

Posted: Wednesday, March 14, 2007 8:45:50 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | WCF

WCF Link List

Architecture Overview

MSDN Forum

WCF Tools

Contract Versioning

Terminology

Integrating WWF and WCF

WCF Developer Home

WCF Team Blog

Posted: Wednesday, March 14, 2007 8:43:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 3.0 | WCF

Design with Users In Mind

We all spend lots of time delving into the technical aspects of our work, but don't forget who we are creating all these wonderful apps for. You need to design your apps to work for the users, not create apps that the users need to work to use.

Required Reading: Four Modes of Seeking Information and How to Design for Them

Posted: Wednesday, January 31, 2007 11:09:29 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Programming | Winforms

WSOD - White Screen of Death in Winforms Designer

I've seen it many times in the past, now it has a name
Posted: Wednesday, January 17, 2007 6:38:07 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio | Winforms

CopySourceAsHTML Clipboard Access Error (Blame the VPC)

I kept getting an error when trying to use CopySourceAsHTML in Visual Studio 2005. The error was that CopySourceAsHTML was unable to access the clipboard. Turns out the problem is when using it in a VPC, and the answer is here.
Posted: Monday, January 15, 2007 10:11:51 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Strange Problems | Visual Studio

Casting Text Data to Members in a Business Object via Reflection

I have a pipe-delimited text file that I am parsing and using to fill a collection of custom business objects. Instead of hard-coding the bits of each pipe-delimited line, I am using an XML file to map data items in the file to object members, like this XML fragment:

<Field>
    <Name>NAMID</Name>
    <Location>0</Location>
    <MapsTo>MemberId</MapsTo>
    <IsRole>false</IsRole>
</Field>

After parsing and matching the data element to the proper member name, I call this function:

public void SetDataMemberValue(string memberName, Member member, string data)
{    // get an instance      
     // of that object's type.
     Type objectType = member.GetType();
     PropertyInfo[] properties = objectType.GetProperties();
     foreach (PropertyInfo property in properties)
    {         if (string.Equals(property.Name, memberName, StringComparison.OrdinalIgnoreCase))
        {
            object[] args = new object[1];
            args[0] = data;
            object result = null;
 
            if (property.PropertyType == data.GetType())
            {
                //The type of the property matches the data's type
                result = data;
            }
            else
            {
               result = property.PropertyType.InvokeMember("Parse", BindingFlags.InvokeMethod, null, result, args);
            }
 
            if (result != null)
            {
                property.SetValue(member, result, null);
            }
        }
    }
}

The tricky bit is the InvokeMember call, which is casting my string to the appropriate type for the property. Of course this is they stylized version of the function, I removed the try-catch bits to make it smaller and readable for the acutal function. You should wrap the InvokeMember call with a try-catch as Parse methods can fail quite hard.

Posted: Monday, January 15, 2007 9:27:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Vista and Visual Studio 2003 - Not Supported

Now that Vista has gone RTM, lots of us are trying to decide when to upgrade. Here is something I have not seen much mention of:

Visual Studio 2003 is not supported in Vista.

This is going to hold back adoption on my work machine. I'm a consultant, I have to do work on whatever platform the client is using, which unfortunately is VS 2003 sometimes. Is VS 2003 going to be relegated to life in a virtual machine from now on?

Posted: Thursday, November 09, 2006 7:42:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

Vista and Visual Studio 2003 - Not Supported

Now that Vista has gone RTM, lots of us are trying to decide when to upgrade. Here is something I have not seen much mention of:

Visual Studio 2003 is not supported in Vista.

This is going to hold back adoption on my work machine. I'm a consultant, I have to do work on whatever platform the client is using, which unfortunately is VS 2003 sometimes. Is VS 2003 going to be relegated to life in a virtual machine from now on?

Posted: Thursday, November 09, 2006 7:42:52 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

Method for Installing WSS 3.0 Beta2 TR as Slipstream

From JOPX on SharePoint 2007.

Also, the WSS-only install for WSS 3.0 is available here.

Posted: Monday, October 23, 2006 7:44:43 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SharePoint

Method for Installing WSS 3.0 Beta2 TR as Slipstream

From JOPX on SharePoint 2007.

Also, the WSS-only install for WSS 3.0 is available here.

Posted: Monday, October 23, 2006 7:44:14 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SharePoint

ASP.Net Single Sign On - Same Domain

This post in the ASP.Net forums has been the best method for me to make a single-sign on work across different sites in the same domain.

You have to set the machine key in the web.config of all sites even on the same physical box.

Posted: Wednesday, October 11, 2006 6:11:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Security

A List of Visual Studio 2005 Hotfixes

A Google search of hotfixes.
Posted: Thursday, August 24, 2006 8:33:33 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

A List of Visual Studio 2005 Hotfixes

A Google search of hotfixes.
Posted: Thursday, August 24, 2006 8:33:27 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

MCMS 2002 Error: The CMS Server license has expired

OK, now that would seem like a pretty straightforward problem, but really it was something else altogether.

Currently I am writing a helper app for MCMS (Microsoft Content Management Server) 2002 to migrate files from another CMS to MCMS. I am using C# and PAPI calls. Everything was fine on the development server. When I moved the app to the staging (QA) server to perform the migration there (you can't use PAPI remotely), the app got an exception the moment it tried to connect to MCMS: "The CMS Server license has expired". Of course immediately I thought the obvious. After a little digging I found this information in the FAQ implying that I didn't have the proper permissions. I had the server admin elevate my permissions and immediately the problem was solved.

The lesson here: "Develop with least privileges!" It will save you headaches later.

Posted: Wednesday, August 02, 2006 8:13:44 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
MCMS

Speaking at the Visual Studio 2005 Experience on July 28th

I will be presenting sessions at the Speaking at the Visual Studio 2005 Experience on July 28th. My sessions will be on Visual Studio 2005 – New Features inside the Microsoft Across America truck. There are still spots available for some of the sessions that day. Sign up before it is too late!
Posted: Monday, July 10, 2006 5:51:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Speaking | Visual Studio

How ADO.Net 2.0 Batch Updates Really Work

An excellent post by Pablo Castro of  the ADO.NET team explaining the mechanics of how batch updates work with ADO.NET 2.0 and Sql Server 2005.
Posted: Friday, July 07, 2006 3:50:09 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

Don't Re-Invent the Wheel - The .NET Developer's Guide to Identity

Learn how to leverage Active Directory in your .Net apps:

The .NET Developer's Guide to Identity

Posted: Monday, June 26, 2006 7:08:41 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Security

A BCL Method to Set a String in Title Case in C#

No need to create a function yourself or reference a VB library: A great post by Rick Strahl:

public static string TitleCase(string input)

{

      return System.Threading.Thread.CurrentThread.

             CurrentCulture.TextInfo.ToTitleCase(input);

}

Posted: Tuesday, May 23, 2006 12:11:44 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

VSTO Action Pane Closing

When creating VSTO documents that use an Action Pane, the Action Pane gets "lost" if you open another non-VSTO document. The Action Pane is hidden by the different document (as it should), but when you switch back to the original VSTO document, the Action Pane does not automatically re-open itself. This can be fixed by handling the ThisWorkbook_WindowActivate event. In this event we can check the state of the Actions Pane and re-display it if necessary:

private void ThisWorkbook_WindowActivate(Microsoft.Office.Interop.Excel.Window Wn)
{
    if (!Globals.ThisWorkbook.ActionsPane.Visible)
    {
        Globals.ThisWorkbook.ActionsPane.Visible = true;
    }

    if (!ThisApplication.DisplayDocumentActionTaskPane)
    {
        ThisApplication.DisplayDocumentActionTaskPane = true;
    }
}

Posted: Tuesday, May 16, 2006 5:48:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Read and Learn

An awesome post by Jessica Fosler about finding memory leaks.
Posted: Tuesday, May 09, 2006 12:19:34 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Performance

Another VSTO ListObject Bug

With extensive use of the ListObject in an Excel VSTO project, I have identified a second actual bug in the ListObject. This one also has to do with pasting data like the previous bug I posted about, but this time data is being lost instead of created erroneously.
Posted: Thursday, April 20, 2006 9:52:24 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Free .Net Event in SE Michigan: Day of .Net

I just learned about a FREE .Net training event being held in Ann Arbor, MI on May 13th, 2006: Day of .Net! Check out the agenda at the site.

It is a one-day event advertised as a One Day Conference on all things .NET by Developers for Developers. Lots of great speakers, starting with Mark Miller of Mondays fame, and lots of great local .Net experts, including great guys like Aydin Akcasu, Nino Benvenuti, Dustin Campbell, Jason Follas, Dave Giard, Charles Stacy Harris III, Darrell Hawley, Jim Holmes, Josh Holmes, John Hopkins, Greg Huber, Paul Kimmel, Alex Lowe, Drew Robbins, Martin Shoemaker, and Bill Wagner.

Posted: Thursday, April 06, 2006 8:32:25 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback

ASP.Net Windows Authentication and 401.2 Errors

I am working on an ASP.Net app that usesWindows authentication for users. I have a certain section of the app, the "Administration" set of pages that I want to exclude from certain roles of users. This is easy using a web.config file, but the unauthorized users get an ugly default 401.2 error page. I would like to have a custom page for that, and surpisingly there was not a ton of information out there on how to do it. In fact, more often than not the answer was "It can't be done."

I did find an acceptable answer in the forums at aspfree.com. Essentially the solution is to handle the Application_EndRequest event in the global.asax and check the status code and authentication of the user. Here is my version:

void Application_EndRequest(object sender, EventArgs e)
{
    if (Response.StatusCode == 401 && Request.IsAuthenticated && Request.Url.AbsoluteUri.Contains("Administration"))
    {
        Response.ClearContent();
        Server.Execute("../NoAccess.aspx?id=Administration");
    }
}

 

I don't believe this method will work with Forms Authentication, I ran across plenty of posts saying that it works differently.

Posted: Tuesday, April 04, 2006 7:28:29 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ASP.NET | Security

Free Contract First Tool - WSCF

Thinktecture has released a Visual Studio 2005 compatible version of their free WSCF tool. WSCF is a Schema-Based Contract-First Web Services code generator. It allows you to design the messages, interfaces and data for contract-first style web services, acting as a replacement for XSD.exe and WSDL.exe. We have been using XSDObjectGen to do something similarly, but WSCF looks like it is much more flexible. For one thing, it generates collections using generics as List<T> instead of the non-type specific ArrayList that XSDObjectGen creates or the even more simplistic arrays that WSDL.exe creates. If you are using .Net 2.0, this is a great step forward for contract-first tools.
Posted: Friday, March 03, 2006 3:48:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

List Databinding Performance With DisplayMembers and ValueMembers

My copy of MSDN magazine arrived last night, and I read the article Practical Tips For Boosting The Performance Of Windows Forms Apps. Good read. Anyway, I was shocked to find out that I have been databinding lists improperly ever since I have been using .Net. I frequently wrote my code like this:

//Bad Code
combobox.DataSource = datatable;
combobox.DisplayMember = "State";
combobox.ValueMember = "Id";

//Good Code
combobox.DisplayMember = "State";
combobox.ValueMember = "Id";
combobox.DataSource = datatable;

Apparenly, order matters very much. In the first example, the combobox binds using the DisplayMember, then rebinds when updated with the ValueMember. In the second example, the binding only happens once.

In our current app, we have two lists that contain thousands of items that need to be bound, so we are binding them during the startup process so the user won't wait when requesting that data. The startup time was reduced by just under 40% by changing the order of the code for binding.

Posted: Wednesday, February 15, 2006 4:36:53 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Performance | Winforms

Adding Images to CommandBarButtons in VSTO

An old VSTO 2003 post by Kathleen McGrath about how to add images to a CommandBarButton. It still works in VSTO 2005. The example uses the AxHost object to convert bitmaps to stdole.IPictureDisp types for Office toolbars.
Posted: Monday, February 13, 2006 10:35:30 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

The Clipboard Ring Rules!

Checking amongst the group of developers I work with, no one knew this trick. I read about it yesterday here. The feature is called the Clipboard Ring, and it is in both Visual Studio 2005 and 2003. Using Ctrl+Shift+V lets you cycle through the last 10 items you have placed on the clipboard. The command is also found in the Edit Menu in and in the Toolbox in VS2003.
Posted: Friday, February 10, 2006 4:52:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Visual Studio

ADO.Net 2.0 Presentation on January 20th

I will be giving a presentation at a Microsoft Developer Care event at their offices in Southfield, MI on January 20th. The event is sponsored by New Horizons and I will be talking about What's New in ADO.Net 2.0. There will be two other talks as well, see the agenda for details.
Posted: Sunday, January 29, 2006 6:26:58 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Speaking

VSTO Excel ListObject Bug

I found an actual bug with the VSTO ListObject in Excel and insertions of data. See this post on the MSDN forums for details.
Posted: Wednesday, January 25, 2006 6:09:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO

Generics and Enums or Enum.TryParse

I have a case where the user is entering strings into the application, and I have to match that string with the values from a given Enum. Normally that is not too difficult of a task, just convert the enum item to a string and compare, but in this instance I have a bunch of enums to do this with, so I didn't want to write a separate function for each enum type. So I figured generics might provide a solution and here is what I came up with, which is loosely based on the idea of int.TryParse:

/// <SUMMARY>
/// Takes a string that represents an enum member 
///   and returns the enum member
/// </SUMMARY>
/// <TYPEPARAM name="T">An Enum</TYPEPARAM>
/// <PARAM name="input">
///  The string that is the enum member name, case does 
///    not matter
/// </PARAM>
/// <PARAM name="returnValue">
/// The value from the enum that matches the string, or the 
/// first value of the enum /// </PARAM>
/// <RETURNS>
/// True when there is a match, false when not
/// </RETURNS>
/// <REMARKS>
/// - When no match the first item in the enum is returned
/// - The where clause attempts to constrain the input of T 
/// at compile time to be an Enum
/// </REMARKS> private bool GetEnumValue<T>(string input, out T returnValue)
where T : struct, IComparable, IFormattable, IConvertible { if(Enum.IsDefined(typeof(T), input)) { returnValue = (T)Enum.Parse(typeof(T), input, true); return true; } else //input not found in the Enum, fill the out parameter
// with the first item from the enum
{ string[] values = Enum.GetNames(typeof(T)); returnValue = (T)Enum.Parse(typeof(T), values[0], true); return false; } }
Posted: Wednesday, December 07, 2005 7:58:05 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Awesome IIS Resource

IISToolshed - thanks to Paschal for pointing it out.
Posted: Thursday, December 01, 2005 7:23:36 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
IIS

Comboboxes and Double-Clicks

The standard combobox control doesn't support the double-click event, as it is actually a combination of more than one control itself. In my case, I am using the combobox in simple mode with a textbox at the top and a permanently open list directly below the textbox. I needed for the listbox below to respond to the user double-clicking a list item. I found a great solution in a Usenet post by Jacques Bourgeois in microsoft.public.dotnet.framework.windowsforms.controls. Essentially the code simulates a double-click using the single-click event and a timer control.

Declare a timer control in your class, and in the load event of the form instantiate the timer set the interval of the timer to the interval of the double-click as set in the user's system:

this.comboDoubleClick = newTimer();

this.comboDoubleClick.Interval = SystemInformation.DoubleClickTime;

In the event handler for the timer, set the code to stop the timer:

this.comboDoubleClick.Enabled = false;

Add code to the single-click event handler to handle the double-click. When the event handler fires, if the timer is not enabled, start the timer (the first click). If the timer is enabled, a previous click has occurred within the system set interval for a double-click. This must be the second click of the double-click, so do whatever you needed the double-click to do and then disable the timer for the next single-click event.

private void Combo_MouseClick(object sender, MouseEventArgs e)
{
   
if (this.comboDoubleClick.Enabled == true)
    {
       
//Do double-click work here
       
this.comboDoubleClick.Enabled = false;
    }
   
else
   
{
       
this.comboDoubleClick.Start();
    }
}

Posted: Thursday, November 10, 2005 6:01:28 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | Winforms

C#, VSTO 2005 and ActiveCell.Offset

Just a quick tidbit about using the Excel object model and C# in VSTO 2005. ActiveCell.Offset (as we know it in VBA, and even VB.Net) is not there in exactly the same way with C#. The syntax for C# is:

ActiveCell.get_Offset(1,1).Value2 = 22

And of course you need to use Value2 instead of Value, it's not like there is any choice there anyway.

Posted: Friday, October 21, 2005 10:18:15 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
Office | VSTO