Capturing the Deleted Text in TextBox when Backspace or Delete Key is Pressed

If you have ever wanted to get the deleted character/text from a textbox when the Backspace key or the Delete key on the keyboard is pressed, you would know that there is no easy way to do that. You can easily get the typed text (using any of the keyboard events like KeyDown, KeyPress etc.), but not the deleted text.

However it is not impossible to achieve this. All you need is some event/method that executes before the KeyDown event is fired. And fortunately there are many.

For this demo I will show you how to do that using the ProcessKeyMessage , but you can use any of the others as well (e.g. WndProc etc.) … Read the full article »

Connecting Windows 7 Workgroup to Windows 2008 Server

We recently upgraded our machines. The old ones were Windows XP running on 32-bit dual core processors. The new ones are with Core-i7 processors and had Windows 7 Professional (64 bit) preinstalled.

In our existing setup, we have one windows 2008 machine and many windows XP machines.  The PCs are connected in a Workgroup, and the server is used mainly as a DHCP server, internet access and for common file sharing. There were no issues till now accessing the Windows 2008 Server from the existing Windows XP machines.

Now, in the new Windows 7 machines we found a peculiar problem. Everything worked as expected, except that we are not able to access the shared folders on windows 2008 server … Read the full article »

Automating the Process of Extracting *.sql Attachments from Emails and Executing them on a set of SQL Server Databases

Recently I was off on a long leave from my work. After returning to office, I found that there are so many emails accumulated in my inbox, and many of them contained SQL script files to be executed on my local SQL Server test databases. Extracting each file into a folder and then executing each of these files (*.sql files) on each database was just like the task I always hate. There were some hundred of these attachments, and each file had to be executed on about 6 databases. So if I do everything manually, it will take me days to finish this.

So I set off for making a script that will automate this. … Read the full article »

The IsNot Operator in VB.NET

One of the most underused operator in VB.NET is the IsNot operator. That’s because there was really no significant use of introducing this operator. All was going well without this operator too. I find that many experienced programmers are still unaware of the existence of this operator in VB.NET.

The old way of doing things was:

If Not object1 Is object2 Then whatever

… Read the full article »

File MIME type / Content Type

I have a webpage that has FileUpload control to upload files to server. The FileUpload.ContentType is also saved in database and later used in other procedures.

Now I need an equivalent functionality in my webservice. I get the files from user in byte array. But how should I determine the content type? I was stuck on this because there is no native .NET way to get an equivalent of the FileContent of the asp.net FileUpload control.

I tried using the urlmon.dll. But the results for FileUpload.ContentType and the urlmon.dll were different. The FindMimeFromData of urlmon.dll and FileUpload.ContentType return different values for same file. … Read the full article »

Visio for Enterprise Architects Installation Hack

Background

We have upgraded to Visual Studio 2008 but are still stuck with Visio for Enterprise Architects 2003 for designing databases. Recently my system started causing some problems, and I decided to format my hard disk and reinstall Windows XP, since it had a lot of obsolete/unnecessary stuff too. So I backed up all data, formatted C drive and installed everything afresh. Finally I started installing my development environment. I installed Visual Studio 2008 and wanted to skip Visual Studio 2005 installation. But the Visio for Enterprise Architects setup won’t let me do that. The setup won’t work until you install Visual Studio 2005.

I really didn’t want to install Visual Studio 2005, since we no longer use it. We have already upgraded all our projects to .NET framework 3.5. (Visual Studio 2008)

The Problem

I’m sure there are many like me who are facing this problem. When you try to install the Visio for Enterprise Architects, without installing Visual Studio 2005/2003, you get the following message, and setup won’t continue further:

You must first install one of the qualified Visual Studio Editions.

In my case, I had already installed Visual Studio 2008, and didn’t want to install Visual Studio 2005, just to fulfill an absurd installation requirement. I know I would uninstall VS 2005 after this setup finishes even if I did, since I won’t be ever using it.

You must first install one of the qualified Visual Studio Editions message

The Solution

I searched for workarounds on the internet and finally hit upon some hints.

This is what I did.

  1. Run Regedit
  2. Backup the entire registry, less something goes wrong.
  3. Create the following registry key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS\VSTD
  4. Inside the VSTD key, create a string value named ProductDir and set it to any value. (I had set it to “1”)
  5. Close Regedit and run the Visio setup. It should now run smoothly.

I created and saved a copy of reg file that inserts the required keys, so that the next time I run into such situations I find this handy. So if you don’t want to follow the above manual procedure, or won’t like to mess around with the registry editor, just download & run the reg file I created.

Download link: VisioEA Registry Hack

Enjoy Hot

What if It doesn’t Work?

Hacks are hacks after all. They may work in one situation and not in others.

This hack worked for me. But from what I read from various resources on the internet, it doesn’t work for everyone. This depends on your version of Visio or Operating System etc.

If the hack didn’t work for you, try the following alternatives:

In the above procedure, step 3, try with these other registry key variations (other steps remain the same). One of these might work for you:

  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\8.0\Setup\VS\VSTD
  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\7.0\Setup\VS\Arch
  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\7.1\Setup\VS\Arch
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\8.0\Setup\VS\VSTD
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\7.0\Setup\VS\Arch
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\7.1\Setup\VS\Arch

A Word of Caution here

  1. Playing with the registry can be harmful. Do whatever you want to do with your registry at your own risk. I take no responsibility for any damages or anything else whatsoever.
  2. As with any other hacks, you may or may not be violating any license terms etc.. I never bothered to looked at that. So, do that at your own risk.
  3. As with any other files, scan downloaded files for viruses. I may not be having the best antivirus in the world and I undertake no responsibility for any damages caused to your system by using the files. Specifically, *.reg files have the ability to cause damage to your system, since they are executable files.

Grouping on one field and sorting on another in Crystal Reports

Today I was stuck with this problem in Crystal Reports. I have the report grouped on some field but don’t want the records to be sorted on that field. Instead I wanted to have it sorted on another field.

The Problem

When you have a group field in the report, crystal report automatically adds the “group by” field in the sort list, and there is no way of removing it. If you click the Record Sort Expert button on toolbar and open the Record Sort dialog, you will see what I mean. You will find your “group by” field already there, and buttons to remove it disabled. Also you can’t lower its sort priority by specifying any other sort condition above it; so this is the first sort condition forcefully, whether you like it or not. I have no idea why Crystal report does this. But in my case I didn’t want the records to be sorted by this field.

The Solution

I couldn’t find anything inside Crystal Reports to solve my problem. Fortunately, since I was using datatable anyways, this is how I resolved my problem.

This was a two step approach:

  1. Some changes in the Crystal Report file.
  2. Some changes in the way we connect it to dataset/datatable.

Setting up things in Crystal Report file

1. Click the Group Expert button on toolbar. This will open the Group Expert dialog box.

Crystal Reports Group Expert Dialog

2. In the Group Expert dialog box, click the Options… button. This will open Change Group Options dialog box.

Crystal Reports Change Group Options Dialog  Crystal Reports Change Group Options Dialog 2

3. Here in the second dropdown, select “in original order” option. Click OK button to close the dialog box.

4. Click OK button in Group Expert dialog box to save changes and close it.

5. Save the report file and close it.

Changes to How we use the DataTable

I modified my VB.NET code to sort the datatable there instead of letting Crystal Reports do it for me. So we pass it a pre-sorted datatable according to our needs.

This is the scaled down version of what I did:

'create datatable
Dim myDataTable As New DataTable
 
'TODO: fill datatable with appropriate data here
 
'set the sort
myDataTable.DefaultView.Sort = "City, CustomerName"
 
'create report document
Dim myReport As New ReportDocument
myReport.Load("C:\ReportTemplates\CustomerReport.rpt")
 
'set datasource
myReport.SetDataSource(myDataTable.DefaultView.ToTable)
 
'now do whatever you want to do with this report.
'e.g. I exported it to disk file, but you may want to show on screen etc.
myReport.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\Reports\CustomerReport.pdf")

Your requirements may not be exactly same as mine. But this is the general approach to follow. (Pay more attention the comments than the code itself)

How This Works

What we basically did is not let Crystal Reports apply its brain for sorting the data. Instead we passed it the sorted data itself. The code is self-explanatory.