Blog

horizontal line graphic

Subscribe to Kevin Southworth's Blog  Subscribe to my RSS feed | Categories | Search

Articles from .NET

HowTo: Programmatically Hide a DotNetNuke Module

Friday, May 16, 2008 @ 10:33 AM :: 121 Views :: 0 Comments ::

I needed to programmatically hide a DotNetNuke module today and I couldn't find any examples of how to do it.  So here's how to do it.  This hides the entire module, including the container and title.

In your Page_Init method in your code-behind, use this little baby:

ContainerControl.Visible = false;

Retrieving DotNetNuke List Items in Code

Monday, September 24, 2007 @ 12:51 PM :: 407 Views :: 1 Comments ::

Today I needed to grab the contents of a DotNetNuke List (Host Settings -> Lists).  Here's the code to grab the "Country" list and DataBind it to a ListBox:

            Dim listController As New ListController

            Dim listEntries As ListEntryInfoCollection = listController.GetListEntryInfoCollection("Country")

 

            lstCountries.DataSource = listEntries

            lstCountries.DataValueField = "Value"

            lstCountries.DataTextField = "Text"

            lstCountries.DataBind()

ASP.NET on Rails!

Tuesday, August 07, 2007 @ 2:07 PM :: 260 Views :: 0 Comments ::

I finally got around to checking out MonoRail last night and I have to say that I am both impressed and excited that this framework exists.  MonoRail basically brings the Ruby on Rails style of programming to the ASP.NET platform.  With MonoRail, you have no ASP.NET page lifecycle, no WebForms, no Viewstate/ControlState, etc.  That might seem like a bad thing, but once you see how MonoRails works (and enforces an MVC architecture) I think you'll see the benefits.  I started web programming with PHP and MySQL and I loved the flexibility and control that PHP can give you as a web programmer.  A lot of the time the ASP.NET and the WebForm model feel too heavyweight to me.  It feels like it's just getting in the way.  I'm really excited to dive deeper into MonoRail and play around with the OR/M and Scaffolding features.  Check out the Castle and the MonoRail projects.

Where are all the open source .NET projects?

Thursday, April 05, 2007 @ 10:25 PM :: 346 Views :: 3 Comments ::
A colleague and I have been discussing lately the relative lack of open-source software projects that are written in .NET languages (normally C# or VB.NET).  We've been searching for a web-based tool to help us with: task tracking, bug tracking, project management, help desk/support tickets, project scheduling, client/customer interface (where clients can login and check status of their projects).

Searching for these types of open-source projects on Google, Sourceforge, and all the usual places turns up a LOT of PHP, Perl, Python, Java projects, but hardly any .NET projects!  However, just because there are a lot of projects out there in these other languages doesn't mean they are any good (as we're finding out).

My feeling about most open-source projects is that they never really get the "spit and polish" of a commercial application.  Of course there are some outstanding open-source projects that rival many commercial offerings (Apache Webserver, Subversion source control, and the Linux Operating System immediately come to mind) but for the most part the projects you see out there were likely written (or at least started) by one developer who was probably motivated by one of the following:
  • Learning a new programming language
  • Needed a program/application to behave in a very specific way
  • The joy of programming just for the fun of it (yes it can be fun!)
The problem with this is that it seems most open-source projects seems to fall in the realm of that first bullet, where the develope is learning a new language and just needs a project to chew on.  As a result, most of the time these projects are always "in development" or they simply aren't up to par in other areas such as Usability, Reliability, or Feature Set.  Also, most of the time the source code is not something you'd want to touch with a 10ft pole!

However, it's when you combine those last two bullets that you can get some great open-source software like Apache or Linux.  These projects are written by smart and dedicated guys (and gals) who are there for the joy of it.

But back to my original question. Where are all the really cool and blog-worthy open-souce .NET applications?  I know there are some great ones out there (DotNetNuke, NUnit, Commerce Starter Kit, SubSonic) but it pales in comparison to other non-Microsoft languages.

Hmmm...maybe I should shut up and start an open-source .NET project....

SubSonic vs. EntitySpaces – A Battle of OR/Ms

Tuesday, January 30, 2007 @ 11:11 PM :: 4116 Views :: 16 Comments ::

I was quite overwhelmed recently when I started researching  OR/M tools for the latest ASP.NET 2.0 project at work.  There are so many to choose from, all with their own unique take on what it means to be a good object-relational mapping tool.  I only wanted to spend a day or two researching/evaluating OR/M tools, and I narrowed it down to SubSonic and EntitySpaces for my final showdown.

SubSonic

I first heard about SubSonic about 6 months ago from one of the many ASP.NET blogs I subscribe to.  The goal of the project is to bring some of the cool RAD tools from the Ruby-on-Rails world into ASP.NET.  One of the nicest features of SubSonic is that it mostly “just works” without too much effort.  There’s no crazy-complicated XML mapping files (I’m looking at you NHibernate…) or mountains and mountains of auto-generated code to dig through (N-Tiers).  SubSonic utilizes a cool feature of the VS2005 and ASP.NET environment called “Build Providers”. All you have to do is make a few adjustments to your web.config file, add a special file to your App_code directory and you’re done!  Whenever you compile/build your VS solution, SubSonic reads your database schema and dynamically generates Data Access classes.

EntitySpaces

I only recently became familiar with EntitySpaces.  A former co-worker of mine really likes the d00dads architecture, the precursor to EntitySpaces.  EntitySpaces takes the code-generation approach, utilizing the popular free code-generation tool MyGeneration.  EntitySpaces is essentially a few .NET dll’s and some MyGeneration code templates.  You load up MyGeneration, open the Entityspaces templates, point them at your database tables, and MyGeneration will spit out a bunch of Data Access and Biz Logic classes in either C# or VB.NET.  My favorite features of EntitySpaces are it Scaffolding support (to auto-generate administration screens for all of your database tables) and its great support for hierarchical data models.

Shot of a scaffold page (notice the drop-down auto-generated for the FK column)

es2_CropperCapture[1].Jpg

SubSonic

Good Stuff

·         Free and Open Source!

·         Easy to get started / mild learning curve

·         Dynamic Queries

·         Strongly-typed wrapper classes for all your stored procedures

·         Active forums, frequent releases

Chinks in the armor

·         Scaffolding support is buggy

·         Doesn’t handle GUID keys very well

·         Weak support for navigating PK/FK relationships

·         Geared towards ASP.NET only (WinForms is possible)

EntitySpaces

Good Stuff

·         Auto-generated scaffolding is very powerful / time-saving

·         Dynamic Queries

·         Very good support for navigating PK/FK collections in code

·         Able to regenerate Data Access code without affecting your custom business logic

·         Serialization of objects for web services, etc.

·         Active forums / support

Frown Face

·         Not free or open source ($80 for Express edition)

·         No strongly-typed access to stored procedures (it is scheduled for next release though)

Final Thoughts

In the end I chose to drop the $80 for EntitySpaces because of its superior Scaffolding and PK/FK Hierarchical support, both of which have been big time-savers so far, allowing me to focus more on the “real guts” of my application instead of Data Access code.  The addition of stored procedure wrappers in the next version will make it even more attractive in my opinion.   However, I’m definitely going to keep an eye on the SubSonic project, since they are adding features all the time.  The biggest things preventing me from using SubSonic right now are the relatively buggy scaffolding support for GUID data types, as well as the weaker support for navigating hierarchical PK/FK collections in code.

Custom DotNetNuke Control Panels

Wednesday, January 24, 2007 @ 2:05 AM :: 388 Views :: 0 Comments ::
This is just a quick note for myself, I may do a full blog post on this topic later (since I haven''t found instructions anywhere on how to do this from anyone else).

I was interested in creating a custom control panel for DotNetNuke (the bar at the top with all the page and module functions).

  1. Create a copy of the .ascx / ascx.cs files of one of the existing control panels in the "website/admin/controlpanel" directory
  2. Add a row in the "ModuleControls" table with ControlKey = CONTROLPANEL:XXX where XXX is your custom name and set the ControlType = -3
Step # 2 should make your custom control panel visible in the Host Settings -> Advanced -> Other -> Control Panel drop-down

Dynamic controls in ASP.NET

Wednesday, January 24, 2007 @ 2:01 AM :: 281 Views :: 0 Comments ::
The other day I had to figure out how to build a dynamic form using ASP.NET.  We were storing the "form definition" of all the different types of controls we''d be supporting in our SQL Server backend database (so far we only support Textbox, Checkbox, and Label, since that''s all the client needs at this point).  My job was to figure out how we''re going to render the page using these dynamic controls, which the user could choose and redefine dynamically using the administration interface.  After a lot of prototyping and proof-of-concept type applications testing out the ASP.NET event model, etc. it turns out that this isn''t too difficult (which is good news, because in PHP this type of thing is fairly simple to implement)  The key things to remember are:
  • Use a Placeholder control as the container for your dynamic controls / form elements
  • You must load / re-add the dynamic controls on every page load, if you do not you''ll get some strange behavior when trying to retrieve the form values
  • Keep the methods/logic for adding the form controls separate from the methods/logic used to populate the controls with data from the database.  I made the mistake of bundling these two things together, and I eventually ran into all kinds of "duplicate control ID" errors from ASP.NET.  Once I separated them out, things were much smoother

Custom Module permissions in DotNetNuke

Wednesday, January 24, 2007 @ 1:54 AM :: 242 Views :: 0 Comments ::

Here''s a nice post from the core team on how to implement custom module permissions for your own modules, and hooking them up to the built-in "permissions grid"

http://dotnetnuke.com/Default.aspx?tabid=825&EntryID=1052

ADO.NET vNext

Wednesday, January 24, 2007 @ 1:53 AM :: 259 Views :: 0 Comments ::

I noticed today that the August CTP release of the new ADO.NET vNext is now available for download.  Don''t know much about this platform yet, other than it''s related to the LINQ technology Microsoft is working on.  This is supposed to be Microsoft''s solution to the ORM/ERM tools that have been out there for a while.  The idea of mapping relational data to object-oriented objects, and being able to issue queries based on objects instead of relational data.

You can check out some screencasts from the ADO.NET team blog:

Part 1

Part 2

More info: http://blogs.msdn.com/adonet/archive/2006/08/15/701479.aspx

Send a file from Excel to ASP.NET web service using VBA macro

Wednesday, January 24, 2007 @ 1:52 AM :: 1403 Views :: 2 Comments ::

The other I had the challenge of figuring out how to add a toolbar button to a MS Excel file that would send the current file to an ASP.NET web service.  The web service could then take some action on the file, such as send it as an email attachment, or log it to a database.

You''ll need the following tools/downloads (in addition to MS Excel and Visual Studio 2003/2005)

Microsoft Office 2003 Web Services Toolkit

  1. Create the ASP.NET Web Service to receive the file. I used VS 2005 to create my webservice, but VS 2003 should work fine also.  The key is to have the web method receive a byte[] array as a parameter, since that is what we will be passing from our client-side VBA code.
            [WebMethod]
    public void ReceiveExcelFileBytes(byte[] data)
    {
    Console.Write(data);
    Stream output = new FileStream(
    @"C:\WINDOWS\TEMP\data.xls",FileMode.Create);
    BinaryWriter outputWriter = new BinaryWriter(output);
    outputWriter.Write(data);
    outputWriter.Close();
    output.Close();
    }
  2. The next step is to write our VBA code inside MS Excel. Create a new Excel file and open it. Open the Visual Basic Editor by pressing Alt-F11. Add a new "Module" and type in the code below:
    Dim sMenu As String

    Sub AddCustomButton()

    Dim oCB As CommandBar
    Dim oCtl As CommandBarControl
    Dim newMenu As Object ''CommandBarControl
    Dim ctrlButton As Object ''CommandBarControl

    sMenu = "Send to Webservice"

    On Error Resume Next
    Application.CommandBars("Formatting").Controls(sMenu).Delete
    On Error GoTo 0

    Set oCB = Application.CommandBars("Formatting")
    Set oCtl = oCB.Controls.Add(
    Type:=msoControlButton, temporary:=True)

    With oCtl
    .BeginGroup = True
    .Caption = sMenu
    .FaceId = 197
    .Style = msoButtonIconAndCaption
    .OnAction = "SaveToWebservice"
    End With

    End Sub
  3. Next we need to hook-up our function to the Workbook_Open event. Double-click on "ThisWorkbook" in the VBA Editor and type in the following for the Workbook_Open event handler:
    Private Sub Workbook_Open()
    AddCustomButton
    End Sub
  4. Make sure have installed the Office 2003 Web Service Toolkit, we''ll be using it to generate a VBA proxy for our ASP.NET webservice. Inside the VBA editor, go to "Tools -> Web Service References" menu and add a reference to the URL of your ASP.NET webservice that was created in step # 1 above. This will generate some VBA code that we can use to call our ASP.NET webservice from VBA.

  5. Now we need to connect our custom toolbar button to some code that actually sends the file across the wire. Jump back to the VBA module (where we have our AddCustomButton() method, and add the following code:
    Sub SaveToWebservice()

    On Error GoTo Error_Handler

    Dim backupFile As String
    Dim fhandle As Long
    Dim webservice As New clsws_ExcelWebService

    backupFile = "C:\WINDOWS\TEMP\file_backup.xls"

    '' Save a backup copy to retain our VBA code
    ActiveWorkbook.SaveCopyAs backupFile

    Dim TypeBinary
    Dim oStream As ADODB.Stream

    '' Create the object
    Set oStream = CreateObject("ADODB.Stream")

    '' Open our file
    oStream.Open
    oStream.Type = adTypeBinary
    oStream.LoadFromFile backupFile

    '' Retreive binary data from the file
    Dim dataLong As Long
    Dim dataBytes As Variant
    Dim dataString As String

    dataBytes = oStream.Read

    '' call the webservice
    webservice.wsm_ReceiveExcelFileBytes (dataBytes)

    oStream.Close

    MsgBox ("Successfully sent")

    Exit Sub

    Error_Handler:
    MsgBox Err.Description &
    " (" & Err.Number & ")",
    vbOKOnly + vbCritical
    Exit Sub

    End Sub

 

Smart Clients in .NET 2.0

Wednesday, January 24, 2007 @ 1:51 AM :: 195 Views :: 0 Comments ::

I found a really good article on CodeProject this weekend on Smart Client development. It goes into a lot of detail on how to implement a Smart Client type application, but it also has some good stuff relating to Design Patterns, and how to implement an “Automation” module similar to MS Word. I haven’t finished the whole article yet, but it looks really informative. Plus you can download all the source code for his sample app :)

http://www.codeproject.com/smartclient/SmartClientSOA.asp

Old School AJAX

Wednesday, January 24, 2007 @ 1:44 AM :: 229 Views :: 0 Comments ::

I''m working on a project right now for a client that uses what I consider to be "old school AJAX" for Classic ASP pages (before .NET).  The main function for AJAX enabled applications utilizes a Javascript function called "XMLHTTPRequest".  The Classic ASP version of XMLHTTPRequest is called RSExecute and let me tell you, it is one tough mother to debug!  Luckily the MSDN documentation provides some help in tracking down Remote Scripting errors, but I was still reduced to healthy amounts of alert() and MsgBox() statements in order to get things working.

It''s interesting to see the progression and history of so-called "new" technologies like AJAX, especially when in this case the functionality has been there for several years (it just needed a cool techie name in order to become more popular).  Microsoft has gotten on-board the AJAX train in .NET using what they call "Client Callbacks" in ASP.NET 2.0.  I''m hoping that Microsoft''s newest API for doing client-side remote scripting is easier to use that RSExecute!