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

SelfSSL and Site ID

SelfSSL is a tool found in the IIS 6.0 Resource Kit. It allows you to generate SSL certificates for a development environment. In all the instructions for using SelfSSL, it describes one of the parameters as "Site ID", where the default value=1, which is the default web site installed on the computer. The Site Id parameter is essentially telling SelfSSL which web site to install the certificate into. Well, if you have multiple web sites, then the default site id is useless. You need the Site Id of the web site where you want the certificate installed. Of course the documentation does not spell this out, and as a non-Admin the Site Id was not an intuitive term for me. But I found that there is a script you can run from the command-line called iisweb.vbs using the /query switch. That will tell you the Site Id. Seeing that, then I realized that the IIS log file folders (in windir\System32\logfiles\) are named according to the Site Id.

Anyway, creating a second certificate for a different site on the same IIS using SelfSSL messes up the SSL cert of first site. This is a known issue apparently, and David Wang has a great post on this problem. The comment further down by Paul Carrig is most useful, as he points out there is a workaround for the SelfSSL and multiple site issue. So I actually found two workarounds:

  1. The technique described by in the aforementioned post:
    1. Install the cert in the first site
    2. Export it to a .pfx file
    3. Install the cert in the second site
    4. Remove the cert from the first site
    5. Re-Import the cert to the first site using the .pfx file

      or
  2. Install the cert in the first site, and export it to a .pfx file. Then import that to the other sites. The down side to this is that the certificate is even less valid for the second sites as now it has an untrusted publisher (me!) and the site name is not a match. The prompt is essentially the same, but in our case one site contains web services which will throw an error if the prompt comes up at all (as it should). The workaround for that is to install the certificate on the client computers as well, which is an acceptable problem for a development enviroment.
Posted: Monday, August 08, 2005 8:27:20 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
IIS | Security

Batch execute SQL files in a directory

Having to excecute hundreds of .sql files in an environment without port 1433 open led me to this nugget of a Usenet post: How to execute multi-file.

Here is the gist of it, the command line for executing all those .sql files with osql:

FOR %i IN (*.sql) DO OSQL -n -U sa -P sapassword -d databasename -i %i

I am sure I could have merged them all into one file or made some sort of batch vbs, but this did the trick nicely.

Posted: Monday, July 25, 2005 5:21:07 AM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
SQL Server

Whidbey Beta 1 to Beta 2 Migration with Typed Datasets

Today we are migrating my project from Whidbey Beta1 to Beta 2 (if you know why this is happening today, go ahead and laugh with us), and our biggest hurdle so far is Typed Datasets.

We used dozens of XSD schemas to create typed datasets. Of course, Beta 2 no longer gives a menu option for creating a typed dataset directly from a schema (see this post in the Fedback Center for Visual Studio). The prospect of converting to the Dataset type of schema was daunting, and moving to the command line for xsd.exe was not going over so well either.

We did discover, however, that you can still generate the dataset using the IDE. In the properties of the XSD file, you can set the custom tool to MSDataSetGenerator. Then you can right-click the XSD file and choose Run Custom Tool. The IDE generates the code for the dataset. Whew!

Posted: Friday, July 01, 2005 4:25:55 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0

Select Distinct in a DataTable (The Whidbey Version)

In my last post I described a “Select Distinct“ function for a datatable. This is a whole lot easier using Whidbey. You can get a distinct table based on a column in the DefaultView of the datatable:

DataTable d = dataSetName.dataTableName.DefaultView.ToTable(true, new string[] { "ColumnName" });

Posted: Wednesday, May 25, 2005 7:06:56 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
.Net 2.0 | ADO.Net

Select Distinct in a DataTable

I needed to perform a “Select Distinct“ on a datatable, not in the database, for binding to a listbox. Found a good solution here. Modified it according to one of the comments to use a hash table so sort order won't matter. Here is my version of the function:

private DataTable SelectDistinct(DataTable sourceTable, string sourceColumn)
{
    DataTable result = null;
    try
   
{
        result =
new DataTable();
        result.Columns.Add(sourceColumn, sourceTable.Columns[sourceColumn].DataType);
       
Hashtable ht = new Hashtable();
       
foreach (DataRow dr in sourceTable.Rows)
        {
           
if (!ht.ContainsKey(dr[sourceColumn]))
            {
                ht.Add(dr[sourceColumn],
null);
               
DataRow newRow = result.NewRow();
                newRow[sourceColumn] = dr[sourceColumn];
                result.Rows.Add(newRow);
            }
        }
       
return result;
    }
   
catch (System.Exception ex)
    {
       
ExceptionManager.Publish(ex);
       
return null;
    }
   
finally
   
{
       
if (result != null)
            result.Dispose();
    }
}

Posted: Wednesday, May 25, 2005 6:26:46 PM (Eastern Standard Time, UTC-05:00)  #    Comments - Trackback
ADO.Net