Tuesday, November 22, 2005

List of Invalid Keyboard Characters for a Windows XP filename

What keyboard characters are not valid for a Windows XP filename?

This has come up several times over the years during my programming tasks when I have tried to automatically generate a filename based on some collection of data. It seems a good time to document this relatively simple question for my future reference as well as yours.

The keyboard characters that cannot be used in a Windows XP filename are:

* Asterisk

Pipe (vertical bar)

\ Back slash

/ Forward slash

: Colon

" Quote

< Less Than

> Greater Than

? Question mark

Hope that helps!
Joe Kunk

Thursday, November 17, 2005

Preparation steps for converting Visual Basic 6 code into Visual Basic.Net 2005

If you have Visual Basic 6 code that you want to convert to Visual Basic.Net, I strongly recommend that you use the Wizard included in Visual Studio 2005, it is much enhanced compared to what is available in Visual Studio 2003.

Note that it is a good investment of your time to go into the Visual Basic 6 source code, make sure that you have the "Option Explicit" statement as the first line of code in each form and module, and then make the needed changes to get a good compile with the correct functionality. This pre-conversion step can significantly reduce the manual changes needed to your code once it is Visual Basic.Net.

Since Visual Basic.Net is a strongly-typed language, any variables in the Visual Basic 6 that are not explicitly declared will be defined as type "Object" in the Visual Basic.Net code and will require type conversion statements to be written manually at locations where they are referenced. It is best to avoid this post-conversion effort by ensuring that the Visual Basic 6 source code has only explicitly defined variables.

Late-bound object references in Visual Basic 6 represent a similar problem. Late-bound references were typically used in Visual Basic 6 to interface to Microsoft Office products or other COM based interfaces in a non-version specific manner. Programs of this type will typically not covert well. For Microsoft Office interface applications, you may want to consider rewriting the software directly in Visual Basic.Net using Visual Studio Tools for Office (VSTO). Note that VSTO requires MS Office 2003. For non-office applications, you will want to consider rewriting the application using early-bound methods by directly referencing the DLL at compile time. If needed, Visual Basic.Net still supports late-bound COM object, but there will be a significant performance penalty.

I hope you find this helpful.

Joe Kunk

Friday, October 14, 2005

A solution for converting C++ MFC code to C# or VB.Net

As Program Director for the Lansing MI based Great Lakes User Group for .Net (http://www.glugnet.org), I received an email from a member that has found a very useful method to accomplish a needed conversion from MFC C++ code into C# or VB.Net. While C++ MFC is outside my area of expertise, I read through his explanation and it sounds like a very useful technique. For those who can benefit, I have included the text of his email below. If you wish to explore this topic further, post a comment and I'll be sure that he is asked to contact you. Thanks. Joe Kunk


As a .NET user group member I wanted to share my experience of"migrating my MFC apps to .NET using C# and VB.NET" so that it will be beneficial for all our members. It might not be an ideal solution for all but I am hopeful it will add at least few new pointers in your knowledge base.

The problem was "How to migrate MFC applications to .NET in C# orVB.NET?" and there were no guidelines or samples. As we know MFC will besupported in Windows Vista (earlier codenamed longhorn) so we can keep MFC apps running for at least few years but question was how to enhanced and use with .NET managed assemblies, keep maintenance low, less compatibility issues, less interops, less performance hiccups and less complicated install program.

Above all new customers were asking on which technology our product wasbuilt? And if answer was "MFC" then we started loosing new business opportunity. Then what to do? What is the trend? Most of C++ programmershave already moved to C# and wish to convert their apps in C# or VB.NET but again there is lack of information on how to do it.

My first problem was ATL or MFC UI conversion to Windows Form resources and there was no help and that was the reason we never went ahead with even prototype test for migration. But thanks to Google where I found acompany called DudeLabs( http://www.dudelabs.com )which has a product"RC Converter" and it changed our migration policy because only in minutes we had our hundreds of dialogs, form views, all standard controls with their properties, menus, string resources and accelerators converted in Windows form resources and we chose our own class name,file name, namespace name and control names naming conventions. We used C# on Visual studio 2005 format but it also generates Visual studio 2003 format and supports C# and VB.NET both.

This quick conversion of our UI gave us ample time to focus on business layer and data layer rewrite.

Now thanks to Microsoft whose application block for SQL Data Access fixed our data layer rewrite in minutes because we were using MS SQLServer 2000. But even if you are using other databases please use SQLData Access application block code as sample and you will be done in hours or in worst case 2 or 3 days.

Business logic rewrite needs to be done manually and we knew that so we started rewriting it and let me tell you writing code in Visual Studio 2005 takes one third or less time as compared to MFC or ATL and then if you have any issues visit http://www.codeproject.com orhttp://www.GotDotNet.com and be assured you will find your solution there and if not the exact answer then at least you will find something to start with. I am really happy as we are near completion of our product migration from MFC to .NET managed world.
As .NET user group and our .NET community always helped me in my migration path I wanted to share it with you all so that it will make your migration at least a little bit easier.

What I learned was - It takes less time and money to migrate to .NET from MFC/ATL than we are estimating in present scenario.

But be careful as only migration to .NET will not increase you sales immediately because this migration first makes sure that your product will survive in future and then it increase your new sales opportunities and gives you flexibility to add new functional modules with less development time, ability to interact with managed world tools and components, enhances performance, keeps you on cutting edge technology, provides you click once deployment and has a very low maintenance cost.

So what you are waiting for?

Wish you good luck with your migration!

Wednesday, October 12, 2005

Application Development Specialist job opening

If you are in the Lansing Michigan area, there is a new job opening for an application development specialist at the Michigan House of Representatives. This is a mid-tier position for a developer with 5-10 years of experience. For more information, visit http://www.house.mi.gov/job_application_development_specialist.asp . Applications must be submitted by October 25th 2005. It is a great opportunity.

Joe Kunk

Monday, October 10, 2005

Finally a great utility for managing Internet bookmarks

I work on several computers, a laptop, a desktop, a server, etc. It has always frustrated me that my Internet Explorer bookmarks are different on each PC. For years I have wanted access to all my saved bookmarks, on any of my computers that I routinely use, or from any other computer via a web page.

I finally found it. The web site http://www.sync2it.com/ allows you to create a free member account where a master copy of all your bookmarks are stored. You download a small utility for your system tray that allows you to upload your current bookmarks and then provides easy one-click access to your bookmarks at any time. Add or delete a bookmark? The other computers are automatically synchronized with the same change. It is as if all the bookmarks are coming from a single shared directory. Wonderful!

If you are on a computer that does not allow you to install software, like a library PC, you can access all your bookmarks as a web page by signing into your account on the Sync2It web site.

And best of all, this service is provided free of charge.

This service has made my internet browsing so much more productive - I just love it. Try it out, I am confident you will be impressed.

Joe Kunk

Thursday, October 06, 2005

A Great Compuware OJ.X Conference

I just got back from the Compuware OJ.X conference in Detroit and it was awesome. Each presentation that I attended was loaded with new and interesting information and presentated by dynamic industry leaders. Compuware made every effort to make this a world-class event and they pulled it off. Without going into a lot of detail, let me confirm that it was definitely worth attending and I strongly encourage you to make it next year if you can. I am hopeful that the presentation slides will be posted to the event web site. Even if you didn't attend, watch their web site at http://www.compuwareojx.com/ and review the slides when they are posted. There is a lot of good information there.

I spoke with several people who mentioned that they make a point to read my blog entries. Thank you for reading! It is nice to know that I have an audience and it helps me stay motivated to continue to post the best information that I can.

Joe Kunk

Wednesday, October 05, 2005

Copy text contents of a listbox to the Windows Clipboard in VB.Net

When debugging a new program, I like to add log style messages to a listbox on a form as a very easy way for me to see what is happening with the program and verify if the proper actions are occurring. Recently I had a program that generated a LOT of messages and I wanted to copy the text contents of that listbox to the clipboard with a button so that I paste the text into WordPad and have a hardcopy record of the program's execution log. As with many things in VB.Net, it turned out to be very easy to do.

In case you have a similar need in the future, the code is listed below for your use. I hope you find it helpful.

Joe Kunk

'Copy contents of a string Listbox to the clipboard
Dim strList(Me.lbStatus.Items.Count) As String
Me.lbStatus.Items.CopyTo(strList, 0)
Dim strClip As String = String.Join(vbCrLf, strList)

A VB.Net function to return the text contained within the first set of quotes in a string

I needed a quick function to return the text within the first set of quotes in a particular string. In case you need a similar function at some point, it is listed below for your use. I hope you find it helpful.

Joe Kunk

'Returns the text within the first set of quotes found
Function GetTextWithinQuotes(ByVal strSource As String) As String
Const Quote As Char = Chr(34)
If strSource.IndexOf(Quote) = -1 Then Return String.Empty
Dim StartPos As Integer = strSource.IndexOf(Quote)
Dim EndPos As Integer = strSource.IndexOf(Quote, StartPos + 1)
If (EndPos - StartPos = 1) Then Return String.Empty
Return strSource.Substring(StartPos + 1, (EndPos - StartPos - 1))
End Function

A better error message from Try-Catch-Finally in VB.Net

I like to use Try-Catch-Finally blocks in my code in order to provide a more pleasant user experience. When I show an error message to the user, I like to include enough detail that if the user sends me a screen image, then I have a good headstart on solving the problem. I have played with several variations of the 'perfect' error message, and finally have settled on the format below that is user-friendly and still provides lots of needed detail information. I hope you find it helpful.

Dim ErrorMsg as string = "I was unable to perform <>." & vbCrLf & "Please make sure to <>." & vbCrLf & "Suggestions go here." & vbCrLf & vbCrLf & "Detailed Error Information below:" & vbCrLf & vbCrLf & " Message: " & exp.Message & vbCrLf & _" Source: " & exp.Source & vbCrLf & vbCrLf & " Stack Trace:" & vbCrLf & exp.StackTrace

Joe Kunk

Tuesday, October 04, 2005

Blank page when setting a tabcontrol's tabpage by its index

I am working on an application that has 30-40 tabs in a tab control. To keep it reasonable for the user, I need to limit the displayed tabs to just the 4-5 tabs that are relevant to the current action.

First I tried the obvious of just setting the visible property of the unwanted tabpages to false. This hid the contents of the tabpage, but the tabpage itself remained visible and in the row of tabs that could be selected by the user. If the tabpage had fully hidden itself as it should have (in my mind), I would have been all set. But instead I had a problem to solve.

To clarify, I have almost 40 tabpages total in the tabcontrol. There are four tabpages that always should be shown in a particular order (tabpages 2-5) and I wanted the first tabpage on the left to be different and selected depending on which item was selected in a tree control on the form.

In other words, I want all 40 tabs on the tabcontrol for ease of maintenance on the form, but to only show 5 of those tabpages at any time and to be able to dynamically change which tabpage from the non-display tabpages was to be shown at the first tabpage, depending on what is selected on a tree control on the form.

The first issue was that I could not insert a tabpage to a certain position. The .add method only adds the tabpage to the end of the existing tabpages collection.

The second issue was that any direct assignment to a tabpage always produced a blank tabpage, i.e., none of its child controls were visible and all attempts to get them to appear failed. That was disappointing as I could have just added a dummy tabpage as the first one and then repeatedly replaced with with the tabpage of current interest as the user moved around the tree control.

Utilimately I created a second non-visible tab control on the form named tcHidden, moved all the tabs over to it at Form_Load, then moved the tabpages between the two controls in the desired order as the user moved around in the tree control. It works well and it is fast enough that the users are happy with it.

The tabcontrol is one of those controls that seems to give me fits, probably because I always try to push it to its limits, so I wanted to post one of my workarounds in case someone else has a similar need. If you found this helpful, please post a comment and let me know. Thanks.

Note that I am using Visual Basic .Net 2003 and Framework v1.1

Monday, October 03, 2005

Attend the Compuware OJ.X conference FOR FREE

I will be attending the Compuware conference in Detroit on Thursday October 6th. It is a great day of learning sessions, plus a chance to see some celebrity faces and some great entertainment including Dennis Miller. And if you enter the GLUG2 code when you register, you can attend for free. I hope to see you there! Go to http://www.compuwareojx.com/ for more info and to register. Some of the promotional info is below for your convenience.

Compuware is pleased to announce that the Premier Application Development Event in the Midwest now features the unbeatable combination of in-depth Java and .NET learning, a distinct management track, leading visionaries AND amazing entertainment.

This year's program features such industry heavyweights as:

Rick Laplante, General Manager of Microsoft Enterprise Tools, Microsoft
Mike Milinkovich, Executive Director, Eclipse Foundation
Keith Landers, CTO -- Application Services, Americas, Hewlett Packard
Joe Dumars, President of Basketball Operations, Detroit Pistons
Renowned authors: Scott Ambler, Jon Kern, Stephen Teilhet, David Herst

And concludes with another one-of-a-kind after-hours experience
kicked off in style with an exclusive performance by one of the premier comedy talents in America, Dennis Miller!

Time is running out to register for this exciting event!

Saturday, August 27, 2005

Converting VB.NET to VB6?

I've just hit an interesting situation for the first time.

I wrote a new program several months ago in VB.Net. Now, I have to update a legacy Visual Basic 6 program and need some routines from that VB.Net program.

There has been a lot of attention on how to best convert from VB6 to VB.Net, but now I am facing the opposite situation. I have to believe that this will be more common as time goes on, as legacy code can take a long time to truly fade away.

I know I can use COM Interop to use the VB.Net code directly from VB6, but I don't want to require that the .Net Framework be installed for users of the VB6 application. The best solution is modify the code to work in VB6. It's going to be interesting, I'll keep you posted...

Joe Kunk

Monday, August 22, 2005

Getting the volume label in .Net

To get the volume label of a particular drive, use the Dir method in the VisualBasic namespace. Note that you can ONLY use the Volume fileattribute if you want to get the volume name. Use of any other attribute will prevent the volume label from being returned. On my system, the DVD drive is my E:\, so the following statement successfully returned the volume label for me:

'Get the CD/DVD volume label
Dim VolumeLabel As String = _
Microsoft.VisualBasic.Dir("E:\", FileAttribute.Volume)

Joe Kunk

Sunday, August 21, 2005

Please feel free to comment on my posts

I just changed the settings on this blog to allow comments by anyone, not just members of blogger.com. I want to encourage comments. If you read one of my posts and have anything to add, please do so. I look forward to the dialog.

Joe Kunk

Using IO.Directory.GetFiles with a filename wildcard

I got an "Illegal characters in path" error on the following statement:
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp\*.txt")
and from the documentation it was not clear to me why I was getting the error.

Turns out that you must use the second overload version of the GetFiles method with two strings if you want to include a wildcard.

In the example above, the two possible correct versions of the GetFiles method include:

Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp")
Dim TxtNames As String() = IO.Directory.GetFiles("c:\temp","*.txt")

The second statement provides the desired result of returning a string array of all filenames with a txt extension in the c:\temp folder. The first statement returns all files in the c:\temp folder which can be scanned with a loop for further processing.

Note that the single string overload verison of GetFiles can only accept a directory name.

I hope this helps clarify a point that managed to confuse me. As usual, it's obvious once you know the answer!

Joe Kunk

Saturday, August 20, 2005

How to set the Xceed LicenseKey property in a class

I have been playing with the capabilities of the Xceed FTP control. I ran into a point of confusion and I wish to share the solution. Note that there was no problem or bug with Xceed's FTP control, I just wasn't clear on how to set the needed LicenseKey property in a class rather than in a form.

All of the Xceed controls require a LicenseKey property be set with a valid license code in order to function. The example on their web site assume that you are using the component(s) on a form and show how to set the LicenseKey property just before the call to InitializeComponent(). I confirmed that this works fine on a form.

I want to write a wrapper class around the FTP control so that I can hide some of the complexity of its feature-rich interface and provide a more user-friendly interface, exposing only those capabilities that I need. Since there is no form, setting the LicenseKey needs to be slightly different and I could not find an example.

Below is what I found to work:

Public Class FTP_Example
Private FTP As Xceed.Ftp.AsyncFtpClient
Public Sub New(ByVal FTPSite As String)
Xceed.Ftp.Licenser.LicenseKey = "My License Key Goes Here"
FTP = New Xceed.Ftp.AsyncFtpClient
End Sub
End Class

I hope you find this tip useful.

Joe Kunk

Xceed is a registered trademark of Xceed Software Inc. http://www.xceedsoft.com/

Friday, August 19, 2005

GLUGnet Presentation 08-18-05

Last night I gave the feature presentation to GLUGnet, the Greater Lansing User Group for .Net. The topic was language enhancements and conversion recommendations for Visual Basic 2005. The Powerpoint presentation is available for free download at http://portal.artemis-solutions.com/glugnet/go/iris/3373/en-US/DesktopDefault.aspx. Download the file named, "GLUGnet August 18, 2005.zip".

There was an error on the example for the CONTINUE statement which has been corrected.

The Internet web address for all the sites I mentioned at the GLUGnet meeting were added as the last slide of the presentation.

Thank you to GLUGnet for allowing me to give this presentation. I learned a lot by doing the research for the presentation and I really enjoyed the experience. GLUGnet is a great user group and I'm very proud to be a part of it.

If you find yourself in the East Lansing Michigan area on the third Thursday of the month, please feel free to join us for free food and drinks and an educational meeting. See the web site http://www.glugnet.org for more information.

Joe Kunk

Thursday, August 11, 2005

Two VB.NET blogs you don't want to miss

Today I ran across two blogs about Visual Basic that are awesome resources.

The first is the blog from the Visual Basic .Net IDE team. From their introduction, "This blog is hosted by the program managers, developers, and testers who work on the Visual Basic Integrated Development Environment (VB IDE). " This blog has an awesome FAQ and further tips on the cool new feature of Code Snippets. Other topics include code generation for overrides, a snippet editor, refactoring tool, new debugger features, and an awesome list of the 10 best new features in Visual Basic 2005. It can be found at http://blogs.msdn.com/vbide/default.aspx

The second is "Don't be Iffy" by Julie Lerman. This is a extensive informal blog by a self-employed programmer who clearly loves programming and Visual Basic.Net. Her personality really comes through on her blog. I think you will find it both informative and enjoyable. http://www.thedatafarm.com/blog/

Joe Kunk

Thursday, July 28, 2005

Oh My! The new My Object in Visual Basic.Net 2005

I have historically favored BASIC in its various forms as my programming language of choice, going back to the very first program I wrote on a HP/1000 teletype terminal in 1978. My one exception is a stint with Borland Delphi (circa version 3) which used Pascal as its language. It is no accident that Anders Hejlsberg, the chief architect for the Delphi product, joined Microsoft in 1996 to be a major player on the .Net development team.

So what does that have to do with the new My object in Visual Basic 2005? It continues the tradition of what has always been best about working in BASIC. While other languages have traditionally been more powerful, BASIC has always excelled at getting useful applications completed quickly. As a business applications developer, my goal has consistently been to deliver a quality application that meets the needs of the users as rapidly as possible and then move on to the next needed solution.

The My object provides much simpler access to commonly needed objects in the .Net Framework Base Class Library. It also adds easy access to functionality that previously required use of the Win32 API. This provides a significant speed improvement in many common development tasks.

The My object has five major subclasses:
  • My.Application
  • My.Computer
  • My.Forms
  • My.User
  • My.WebServices

If you want to learn more specifics about the My object, see the July 2005 article in MSDN Magazine, available at http://msdn.microsoft.com/msdnmag/issues/05/07/My/default.aspx.

I mentioned earlier that prior versions of BASIC often traded power for productivity. With Visual Basic.Net 2005, this is no longer the case. The faithful BASIC developers can now have their cake an eat it too. This is an exciting time to be a developer!

Joe Kunk

Friday, July 22, 2005

When is True not True?

When saving a boolean value to a Microsoft® SQL Server 2000 database. In SQL Server 2000, boolean values are represented as data type "bit", with valid values of numeric 0 or 1. When building a SQL INSERT or UPDATE statement, we need to convert a value of TRUE or FALSE easily to a 1 or 0 respectively.

I have found the easiest way is to use the IIF command. Depending on your coding preferences, you should find one of the two choices below will work well for you:

Dim MySQLBoolean as string = IIF(MyBoolean, "1", "0")
Dim MySQLBoolean as integer = IIF(MyBoolean, 1, 0)

Compared to an IF-THEN-ELSE approach, I like the IIF approach since it delivers the desired result in a single line of code.Readabilityy in code is very important, but with all other things being equal, one line of code is generally more readable than five lines of code.

Joe Kunk

Thursday, July 14, 2005

The Power of Panels in ASP.NET

It is fairly common that it takes several pages to be presented to the user to complete a single logical task within a web application.

Say you have a collection of free email newsletters that you want to offer to your site visitors. If a visitor clicks on the link to select one or more newsletters, you may well present:

[Screen 1] a checklist of the newsletters to choose from with a Submit button, then

[Screen 2] a list of just the newsletters selected with a confirmation button, then

[Screen 3] a printer friendly listing of the selected newsletters along with information on how to change or cancel subscriptions and a nice thank you for subscribing to your site newsletters.

Prior to ASP.NET, you likely would have written these as three separate ASP pages; Screen 1 posts to Screen 2 which posts to Screen 3. Easy enough, but it certainly cluttered up the folders on your web server and tracking logic errors was more difficult across three separate source files.

Now with ASP.Net, all three screens can easily be coded into individual panel objects, all within the same .ASPX web page. The code-behind file makes the needed panel visible and sets the visibility of the other panels to false. The user still sees three different screens in sequence but coding is greatly simplified since it is all contained within a single .vb or .cs code-behind file.

I have used this technique in several web applications and it works great. The invisible panels are not included in the final page to the browser so the download times remain tight. I hope you find this tip very useful.

Joe Kunk

Wednesday, July 13, 2005

Visual Studio Tools for Office - A Great Thing Soon

I recently spent some time checking out the Visual Studio Tools for Office product, a.k.a. VSTO. It allows Visual Studio developers to add features and capabilities to MS Word, MS Excel, and with the release of Visual Studio 2005, also MS Outlook.

The advantage is that the code to add features or capabilities to these environments can be written fully in Visual Studio using standard C# or VB.Net code with full IntelliSense assistance and all the other advantages of the .Net framework. No need to learn VBA (Visual Basic for Applications) or macros to be productive.

The disadvantage is that VSTO only works with Office 2003 or later. This makes it unsuitable for widespread commercial applications at this time. A small disadvantage is that your assembly must accompany the document as it is moved around the network or emailed in order to maintain the functionality.

Conclusion: VSTO and the Visual Studio integration in SQL Server 2005 are key steps toward the programmer's nirvana of "learn one tool well and use it everywhere". Its impact will be even more positive as the majority of home and business users upgrade to Office 2003 or later.

Joe Kunk

Tuesday, July 12, 2005

VB.Net Modules in ASP.NET - Trick or Treat in July

Here is the story of a feature in VB.Net that is at the same time very useful and potentially very dangerous.

Microsoft carried the construct of a Module forward from Visual Basic 6 into VB.Net (reluctantly as I understand it). A popular feature among VB6 programmers, it can be viewed as a global class available to all other forms and classes. VB6 programmers commonly used it to hold global variables and methods that would be needed by multiple forms. No instantiation needed, it was just there and global. Very convenient.

VB6 was used primarily to write single-user desktop windows applications. Yes, with the proper level of skill and prayer it could be used for more advanced purposes, but it truly shined as a way to quickly deliver high-quality desktop applications. In a single user environment, a shared global module is not a problem. Use of a module in a single user VB.Net application is still not a problem for the same reason.

Now consider the impact of a module in an ASP.Net application running on a IIS web server. Herein lies the power and the danger.

First the danger. Like before, a module is a class that automatically global to the entire application without requiring any instantiation. But now that single application is being used simultaneously by potentially hundreds or thousands of users. See the problem yet? Any variable declared at the module level is single-instance shared global among all users. If you casually define a module level variable of 'UserName' and base your security permissions on that, you will experience tremendous security issues as incoming users take on whatever security permissions were enabled by the last client that set the 'UserName' variable. Ouch!

Now the power. Modules are a great way to share single-instance methods for very efficient memory usage in VB.Net web applications. Only one copy of each module method is loaded in memory for all users of the application. As long as each of these modules are designed with shared usage in mind and do not depend on any static variables or try to maintain state across calls, this can be a very powerful and efficient design strategy.

Conclusion: In VB.Net web applications, use module level variables with great care, or not at all if possible. Use module methods with care to ensure that they can be safely shared.

I hope you find this information helpful. I wish I had known it earlier and saved myself some grief. Your comments are welcome.

Disclaimer: This post is based on some painful lessons learned from personal experience and not the result the detailed research on the topic. All of the statements in this post are correct to the best of my knowledge but please verify any use of this information with sufficient testing in your particular environment.

Joe Kunk

Getting a DataView to work in an ASP.Net WebForm

With WinForms, I have consistently used dataview controls to allow me to quickly change the sort order or filter of a dataset as seen in a datagrid. It has always worked well for me.

I have not been nearly as successful with WebForms. Whenever I placed a dataview control on a WebForm, it would honor the initial settings of the dataview, but then ignore any runtime changes to those settings. I confirmed that I was properly filling the dataset after each form post.

So how is it that essentially the same exact steps work fine in Windows, but fails in IIS? To get around it I would dynamically compose a new SQL query and load the dataset to match the required sort and filter. This required more coding into the WebForm than really should have been necessary.

I searched extensively for a resolution to this situation but did not find one. Finally, I learned that the trick is to refrain from using the design-time property settings for the dataview when used in a WebForm. Leave the needed properties of the dataview blank and set them only at run-time within code. In this way, it will honor each change in setting and provide the same flexibility to quickly and easily change the view of the data as seen in the datagrid.

Please post a comment to request sample code that illustrates this if you want to see some. I'll put together a good example if there is interest.

Joe Kunk

C#.Net versus VB.Net

This is one of the first issues a developer will face when making the commitment to begin working with the .Net platform. Which to use as your primary development language?

There may be external factors that will push you toward one choice over the other, such as standards in your workplace, a large legacy codebase of C++ or VB, or even the personal preference of your mentor. Since the .Net framework is shared by all .Net languages, it is essentially a toss-up. There are functional differences between the two languages, but they are minor. The good news is that the consistent .Net framework method names between both languages makes it relatively easy for a VB.Net programmer to read C# code, and for a C# programmer to read VB.Net code.

I prefer to work in VB.Net, simply because I have worked in Visual Basic for years and am very comfortable with that style of coding. That said, I can work in C# with only slightly more effort and I think you would find the same to be true. I have seen several surveys over the last year on this issue and developers are pretty evenly split among the two, with professional developers slightly in favor of C#, probably due to the strong presence of C++ code in commercial software applications.

If you have the freedom to make this choice yourself, then choose the language that you are most comfortable in and know that you are in good company with either choice. Learning to be productive in .Net application development is challenging enough, there is no need to complicate it with unnecessary worry about which language to work in.

Joe Kunk

Monday, July 11, 2005

Welcome to JBK.Net

The goal of this BLOG is to share my experiences as a professional application developer and as a board member for our local .Net developer user group.

I have been programming since 1978 and have watched application development evolve from very humble beginnings to the depth & breadth of what Microsoft's .Net environment has to offer today. There is intense joy and pride in delivering an elegant application to the user and knowing that it is among the best software available anywhere for that purpose. I felt that joy with my first program in 1978 and I still enjoy that feeling every time I deliver a new application. That feeling, at least in part, is what drives me to be the best programmer that I can be, and continue to strive to deliver an ever more exciting application next time.

I firmly believe that the .Net platform is the most productive application development platform available today. By taking advantage of its rich framework, I can create applications in a reasonable timeframe that I would never have even attempted before. It has expanded my horizons as a developer immensely. It is an exciting time in the application development world.

By sharing my experiences with .Net, both good and bad, I hope to help others become more productive and effective with .Net.

I will share my mistakes so that others can avoid them. I will share my questions when I am struggling, so we can learn together. I will share my successes so that others can add to their knowledge and skills.
Like most developers, what I don't know about .Net far exceeds what I know. I expect to learn a lot from the feedback and comments of the readers of this blog and I truly look forward to the dialog.

Welcome to JBK.Net. I appreciate your company and companionship on the shared quest to become skilled and productive .Net developers.

Joe Kunk